function ConfigFun() {
    var currentHost = window.location.host;
    var host = '//ajax.huke88.com';

    if (currentHost == 'tthk.huke88.com') {
        host = '//ajax1.huke88.com';
    }

    if (currentHost == 'tthk2.huke88.com') {
        host = '//ajax2.huke88.com';
    }

    if (currentHost == 'tthk3.huke88.com') {
        host = '//ajax3.huke88.com';
    }

    var config = {
        searchUrl: host + '/statistics-search/statistics',
        searchClickUrl: host + '/statistics-search/click',
        searchPlayUrl: host + '/statistics-search/play',
        searchPlayRestrictUrl: host + '/statistics-search/play-restrict',
        searchWatchContentRestrictUrl: host + '/statistics-search/watch-content-restrict',
        searchWatchContentUrl: host + '/statistics-search/watch-content',
        searchDownloadSourceUrl: host + '/statistics-search/download-source',
        searchDownloadSourceRestrictUrl: host + '/statistics-search/download-source-restrict',
        searchDownloadMaterialUrl: host + '/statistics-search/download-material',
        searchDownloadMaterialRestrictUrl: host + '/statistics-search/download-material-restrict',
        searchWordsUrl: host + '/ajax/search-hot-words'
    };
    return config;
}

var Config = new ConfigFun();

/**
 * 阿里云统计页面按钮点击
 */
(function ($, window, document) {
    $.fn.aliLoggerClick = function () {
        var logHost = 'cn-shanghai.log.aliyuncs.com';
        var logProject = 'huke';
        var logStore = 'web_click_log';

        var logger = new window.Tracker(logHost, logProject, logStore);

        var uid = Param.uid;
        var uv = Param.uv_id;
        $(this).on('click', function () {
            var identify = $(this).attr('data-bind-click-identify');
            logger.push('uid', uid);
            logger.push('uv', uv);
            logger.push('identify', identify);
            logger.logger();
        });
    };

})(jQuery, window, document);


/**
 * 工具类
 * zeroPoint    当天23:59:59时间对象
 * @type {{}}
 */

var Tools = {
    'zeroPoint': function () {
        var curDate = new Date();
        var curTamp = curDate.getTime();

        //当日23:59:59的时间戳
        var curWeeHours = new Date(curDate.toLocaleDateString()).getTime() - 1;

        //当日已经过去的时间（毫秒）
        var passedTamp = curTamp - curWeeHours;

        //当日剩余时间
        var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;

        var leftTime = new Date();
        leftTime.setTime(leftTamp + curTamp);

        return leftTime;
    },

};

/**
 * Created by Mr.D on 2017/6/7.
 */
$(function () {
    var renderingEndTime = (new Date()).valueOf();
    var bind_name = 'input';
    var search_count = 0;
    var last_search_word = '';

    var lazyloadError;
    var lazyloadCan;
    // 头部软件入门下拉懒加载图片
    $('#new-header .rjrm-list').hover(function() {
        var a = $(this).find('.lazy').length;
        if (a) {
            if (!lazyloadCan) {
                $(this).find('.lazy').lazyload()
                lazyloadCan = 1
            }
        }else{
            lazyloadError = 1
        }

    });

    var search_key_dowm_index = -1;//联想词上翻下翻index

    if (Param.hasOwnProperty('activityOldUser20220311')) {
        if (Param.activityOldUser20220311.hasOwnProperty('isShowBig') && Param.activityOldUser20220311.isShowBig) {
            watchPopupShow("middle-year-500");
        }
    } else if (Param.hasOwnProperty('activityNewUserMYN')) {
        if (Param.activityNewUserMYN.hasOwnProperty('isShowBig') && Param.activityNewUserMYN.isShowBig) {
            watchPopupShow("middle-year-new");
        }
    }


    //导航软件入门&设计教程下拉
    (function () {

        function loadNavSoftwareList() {

            var $container = $("#new-header .rjrm-list .top-con");

            if ($container.hasClass('hasLoading')) {
                return false;
            }

            $.ajax({
                url: Url.navSoftwareList,
                method: 'get',
                dataType: 'json',
                beforeSend: function () {
                    $container.addClass('hasLoading');
                },
                xhrFields: {
                    withCredentials: true
                },
                success: function (response) {
                    if (response.code === 200) {
                        $("#new-header .rjrm-list .top-con .rjrm-wrap").html(response.software);
                        $("#new-header .sjjc-list .top-con .sjjc-wrap").html(response.design);
                        $("#new-header .zybg-list .top-con .zybg-wrap").html(response.office);
                        $("#new-header .bckf-list .top-con .bckf-wrap").html(response.programe);
                        $("#new-header .aigc-list .top-con .aigc-wrap").html(response.aigc);
                        $("#new-header .cztk-list .cztk-wrap").html(response.career);
                        $("#new-header .top-con-classify").html(response.classify);
                        if (lazyloadError) {
                            $('#new-header .rjrm-list .lazy').lazyload()
                        }
                        // 导航栏软件入门里分类切换
                        $("#rjrm-main .rjrm-list ul li").on("mouseover",function () {
                            $(this).addClass("on").siblings().removeClass("on");
                            if ($(this).index() === 0) {
                                $("#rjrm-main .rjrm-rMain .hot-list").show();
                                $("#rjrm-main .rjrm-rMain .com-list").hide();
                                $("#rjrm-main .rjrm-rMain").removeClass("over-y");
                            } else {
                                $("#rjrm-main .rjrm-rMain .hot-list").hide();
                                $("#rjrm-main .rjrm-rMain .com-list").show();
                                $("#rjrm-main .rjrm-rMain").addClass("over-y");

                                var classid = $(this).attr('data-id');
                                $('#new-header .nav-list .rjrm-wrap .rjrm-main .rjrm-rMain .com-list > div').each(function(){
                                    if ($(this).attr('data-id') == classid) {
                                        $(this).removeClass('hide');
                                        if (!$(this).hasClass('ln')) {
                                            $(this).find('.lazy').lazyload();
                                            $(this).addClass('ln');
                                        }
                                    } else {
                                        $(this).addClass('hide');
                                    }
                                });
                            }
                        });

                        // 导航栏设计教程里分类切换
                        $('.sjjc-wrap:visible .list').hover(function () {
                            $(this).addClass('active').siblings().removeClass('active');
                        });

                        $('.cztk-list').hover(function () {
                            $(this).find('.lazy').lazyload();
                        });
                        $('.cztk-list').find('.lazy').lazyload();

                        //隐藏相关信息
                        if(Param.UserVipIdentifyNum != 4){
                            if(Param.UserVipIdentifyNum == 0){
                                $(".navDesignRechargeContainer").removeClass('hide');
                            }else{
                                if(Param.userHasUpgrade == 1){
                                    $(".navDesignUpgradeContainer").removeClass('hide');
                                }else{
                                    $(".navDesignRechargeContainer").removeClass('hide');
                                }
                            }
                        }

                        //隐藏相关信息
                        if($.inArray(Param.UserVipIdentifyNum, ['3', '4']) !== -1){
                            $(".userVipIdentifyClass").addClass('hide');
                        }
                    } else {
                        // alert('系统出错，请联系客服解决');
                    }
                }
            });
        }

        // 消息下拉 刷新
        $("#new-header .rjrm-list").on('mousemove', function () {
            loadNavSoftwareList();
        });

        loadNavSoftwareList();
    })();
    //弹窗关闭
    $('.qt-tg').on('click', '.close', function () {
        $('.qt-tg').addClass('hide');
    });
    //昨日注册次日回访用户优惠购活动
    $('#right-bar .tips-classify-r .close').on('click', function () {
        $('#right-bar .tips-classify-r').addClass('hide').attr("data-show",1);
        $('#right-bar .cz small').removeClass('hide');
        $.ajax({
            url: Url.returnVisitUserCloseRecord,
            data: {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')},
            method: 'post',
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            success: function () {
            }
        });
    });
    $('#right-bar .cz,#right-bar .tips-classify-r').hover(function () {
        if ($('#right-bar .tips-classify-r').attr("data-show") == 1) {
            $('#right-bar .tips-classify-r').removeClass('hide');
        }
    },function () {
        if ($('#right-bar .tips-classify-r').attr("data-show") == 1) {
            $('#right-bar .tips-classify-r').addClass('hide');
            $('#right-bar .cz small').removeClass('hide');
        }
    });

    //点击搜索框
    $('.header-search .search-m .txt').click(function () {
        var bdw = $(window).width();
        if ($(this).val() != ''){
            $('.header-search .search-win div').addClass('hide');
            getAssociationalWord();
        } else {
            $('.header-search .search-win').removeClass('hide');
            $('.header-search .search-win div').removeClass('hide');
        }

        $('.header-search  #search_word_list').remove();
        $('.header-search .search-win .search-list').removeClass('hide');
        $('.sign-opt-mask').show();
    });

    $(".cashbackActivitySearchBanner").on('click', '.a-close', function () {
         $(".cashbackActivitySearchBanner").addClass('hide');
    });

    //监听搜索框输入
    if (navigator.userAgent.indexOf("MSIE") != -1){
        bind_name = 'propertychange';
    }

    $('.search-m .txt').bind(bind_name, function(){
        var this_count = ++search_count;
        var $this = $(this);
        setTimeout(function(){
            if (search_count == this_count) {
                if($('.sign-opt-mask').css('display') == 'none'){
                    if($this.val().length == 0) {
                        return false;
                    }
                    $('.header-search .search-m .txt').click();
                } else {
                    getAssociationalWord();
                }
            }
        }, 250);
        recommendSearch($this);
    });
    //静音提示
    try {
        if (Param.hasOwnProperty('videoMuteIdentify') && Param.videoMuteIdentify == '1') {
            $(".video-frame,.liveCover,.video-all .video-body").append('<div class="dVideoTips">为确保更好的学习效果，我们正在优化讲师讲解的音频，当前教程播放时将无声音，您可通过视频字幕学习<span class="dclose"></span></div>')
            $(".video-frame,.liveCover,.video-all .video-body").append('<div class="dtipsBtn"><span class="dtipsIcon">!</span></div>')
            $(".dVideoTips .dclose").click(function (e) {

                $('.dVideoTips').stop().animate({
                    left: "-1000px"
                }, 600, function () {
                    $('.dtipsBtn').stop().animate({
                        left: '0'
                    }, 300).show();
                });

                e.stopPropagation();
            })
            $(".dtipsBtn").click(function (e) {
                $('.dtipsBtn').animate({
                    left: '-40px'
                }, 100).show();
                $('.dVideoTips').stop().animate({
                    left: "0px"
                }, 600);

                e.stopPropagation();
            });
        }
    } catch (e) {
        console.log(e)
    }


    //搜索联想词
    function getAssociationalWord() {
        var timestamp = $('#search-identify').val();
        var pageType = $('#search-identify').attr('pageType');
        var search_word = $('.header-search .search-m .txt').val();
        last_search_word = search_word;
        search_key_dowm_index = -1;
        if(search_word == ''){
            $('.header-search .search-m .txt').click();
        } else {
            $.get(Url.search,{word:search_word}, function(res){
                if (res.code == 200 && last_search_word == search_word){
                    if(res.data.lists.length == 0){
                        $('.header-search .txt').css({'border-radius': '5px'});
                        $('.header-search .search-win').addClass('hide')
                        $('.header-search  #search_word_list').remove();
                    } else {
                        $('.header-search .search-win').removeClass('hide');
                        $('.header-search  #search_word_list').remove();
                        $('.header-search .search-list div').addClass('hide');
                        var html = '<div class="list-m " id="search_word_list">';
                        if (pageType *1 == 2) {
                            $.each(res.data.lists,function(k, v){
                                if (v.id == 0) {
                                   html = html + '<p><a href="/search/live?keyWorld='+ v.word +'&identify='+ timestamp +'" data-words="'+ v.word +'" class="record-word" data-words-id="' + v.id + '">'+ v.highlight +'</a></p>';
                                } else {
                                   html = html + '<p><a href="/live/'+ v.id + '.html?source=searchbox" data-words="'+ v.word +'" class="record-word" data-words-id="' + v.id + '">'+ v.highlight +'</a></p>';
                                }
                            });
                        } else {
                            $.each(res.data.lists,function(k, v){
                                if (v.id*1 == 0) {
                                   html = html + '<p><a href="/search/video?keyWorld='+ v.word +'&identify='+ timestamp +'" data-words="'+ v.word +'" class="record-word" data-words-id="' + v.id + '">'+ v.highlight +'</a></p>';
                                } else {
                                   html = html + '<p><a href="/live/'+ v.id + '.html?source=searchbox" data-words="'+ v.word +'" class="record-word" data-words-id="' + v.id + '">'+ v.highlight +'</a></p>';
                                }
                            });
                        }
                        html = html + '</div>';
                        $('.header-search .search-list').append(html);
                    }
                }
            },'json');
        }
    }

    //联想词上翻下翻
    $("#new-header .header-search .txt").on('focus', function(){
        $('#new-header .header-search').addClass('focus');
        var _this = $(this);
        document.onkeydown=function(event){
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if(e && (e.keyCode === 38 || e.keyCode === 40))
            {
                //上翻
                if(e && e.keyCode === 38){
                    search_key_dowm_index--;
                    if(search_key_dowm_index < 0){
                        search_key_dowm_index = $('#search_word_list p').length - 1;
                    }
                }
                //下翻
                if(e && e.keyCode === 40){
                    search_key_dowm_index++;
                    if(search_key_dowm_index >= $('#search_word_list p').length){
                        search_key_dowm_index = 0;
                    }
                }
                $('#search_word_list > p').eq(search_key_dowm_index).addClass('bg-gray').siblings().removeClass('bg-gray');
                var text = $('#search_word_list > p').eq(search_key_dowm_index).children('.record-word').attr('data-words');
                var id = $('#search_word_list > p').eq(search_key_dowm_index).children('.record-word').attr('data-words-id');
                if (text != undefined)
                {
                    _this.val(text);
                }
                _this.attr('live-ad-id', id); // 直播广告推荐

                //光标禁止移动
                event.preventDefault();
            }
        };

        recommendSearch(_this);

    });

    evTimeRecommendSearch = 0;
    // 搜索课程||直播推荐
    function recommendSearch(_this)
    {
        if (Param.uid == 0) {
            return false;
        }
        if (_this.val() !== '') { //搜索框有记录的情况
            return false;
        }
        var now = +new Date();
        if (now - evTimeRecommendSearch < 5000) {
            return;
        }
        evTimeRecommendSearch = now;
        var timestamp = $('#search-identify').val();
        $.ajax({
            type: 'get',
            url: Url.searchRecommend,
            dataType: 'json',
            xhrFields: {
                withCredentials: true
            },
            success: function (s) {
                if (s.status == 200) {
                    if (s.data.length == 0) {
                        _this.parent('.search-m').parent('.header-search').find('.search-list .recm-title').remove();
                        _this.parent('.search-m').parent('.header-search').find('.search-list .recm').remove();
                    } else {
                        $('.search-list .recm').html('');
                        var html = '';
                        $.each(s.data, function(k, v) {
                            if (v.type == 'live') {
                               if (v.live_status*1 == 1) {
                                  html += '<p><a href="/live/'+ v.id + '.html?source=searchbox"><span class="rank-icon"><i></i><i></i><i></i></span>' + v.title + '</a></p>';
                               } else {
                                  html += '<p><a href="/live/'+ v.id + '.html?source=searchbox">直播课：' + v.title + '</a></p>';
                               }
                            } else {
                               html += '<p><a href="/course/' + v.id + '.html?key='+ v.title +'&recommendSearch=1&identify='+ timestamp +'">' + v.title + '</a></p>';
                            }
                        });
                        //_this.parent('.search-m').parent('.header-search').find('.search-list .recm-title').removeClass('hide');
                        _this.parent('.search-m').parent('.header-search').find('.search-list .recm-title').remove();
                        _this.parent('.search-m').parent('.header-search').find('.search-list .recm').remove();
                        _this.parent('.search-m').parent('.header-search').find('.search-list').append('<div class="list-head recm-title"><h3 class="rec"><i></i>搜索推荐</h3></div>');
                        _this.parent('.search-m').parent('.header-search').find('.search-list').append('<div class="list-m recm clearfix"></div>');
                        _this.parent('.search-m').parent('.header-search').find('.search-list .recm').html(html);
                    }
                } else if (s.status == 201) {

                } else {
                    //_this.parent('.search-m').parent('.header-search').find('.search-list .recm-title').addClass('hide');
                    _this.parent('.search-m').parent('.header-search').find('.search-list .recm-title').remove();
                    _this.parent('.search-m').parent('.header-search').find('.search-list .recm').remove();
                }
            }
        });
    }

    $("#search-wrap .search-input .txt,#new-header .header-search .txt").on('blur',function () {
        $('#search_word_list > p').removeClass('bg-gray');
        $('#new-header .header-search').removeClass('focus');
    });

    $('.header-search').on('click', '.search-win', function (b) {
        b.stopPropagation();
    });
    $(document).click(function (event) {
        if (event.target.className != $('.txt').selector.substring(1)) {
            $('.search-win').addClass('hide');
            $('.sign-opt-mask').hide();
        }
    });
    $('.list-m').on('click', '.close', function (b) {
        $(this).parents('p').remove();
        b.stopPropagation();
    });

    /**
     * 搜索记录删除(清空/单条)
     */
    $('#empty-btn').on('click', function () {
        $.get('/search/del-cookie', {name: 'qingkong'}, function (data) {
            $('#record-empty').children('p').remove();
        }, 'text');
        $('#record-empty').addClass('hide');
        $('#empty-record').addClass('hide');
    });

    //删除单条cookie
    $('.history_search_keywords .del-btn').on('click', function (e) {
        e.stopPropagation();
        var _this = $(this);
        $.get('/search/del-cookie', {name: $(this).parents('p').find('a').html()}, function (data) {
            var keyword_index = _this.parents('p').index();
            $(".search-head .history_search_keywords p").eq(keyword_index ).remove();
            $(".header-search .history_search_keywords p").eq(keyword_index ).remove();
            $(".search-bottom .history_search_keywords p").eq(keyword_index ).remove();
        }, 'text');
        if (_this.parents(".history_search_keywords").children().length == 1) {
            $('.history_search_head').remove();
            $('.history_search_keywords').remove();
        }
    });

    //清空搜索
    $('.history_search_head').on('click', '.clear-btn', function () {
        $.get('/search/del-cookie', {name: ''}, function (data) {
            $('.history_search_head').remove();
            $('.history_search_keywords').remove();
        }, 'text');
    });

    //搜索词点击统计
    $('.hot-word').on('click', function () {
        var id = $(this).attr('data-id');
        var words = $(this).attr('data-words');
        $.ajax({
            type: "post",
            url: Config.searchWordsUrl,
            data: {
                id: id,
                words: words,
                sources: getQueryString('sem') == null ? 0 : 1,
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
            },
            dataType: "json",
            success: function (message) {
                console.log(message);
            }
        });
    });

    // 头部搜索框的,placeholder推荐搜索
    var hotEles = $('#new-header .header-search .search-win .search-list .list-m.hotm .hot-word');
    var hotobject = [];
    hotEles.each(function (item) {
        var hotType = $(hotEles[item]).attr('hot-type');
        var dataId = $(hotEles[item]).attr('data-id');
        if (hotType*1 == 1) {
            hotobject.push({'dataId' : dataId, 'hotType' : 1, 'title' : '热搜：' + $(hotEles[item]).text().replace(/\s*/g,'')});
        } else {
            hotobject.push({'dataId' : dataId, 'hotType' : 2, 'title' : $(hotEles[item]).text().replace(/\s*/g,'')});
        }
    });

    // 加载即开始展示首个热词或者直播课程
    if (hotobject.length) {
        var searchDom = $('#new-header .header-search .txt');
        searchDom.attr('placeholder', hotobject[0].title);
        searchDom.attr('hot-type', hotobject[0].hotType);
        searchDom.attr('data-id', hotobject[0].dataId);
    }

    // 循环替换
    var placeholderIndex = 1;
    var placeholderTimer = setInterval(function () {
        if (hotobject.length) {
            searchDom.attr('placeholder', hotobject[placeholderIndex].title);
            searchDom.attr('hot-type', hotobject[placeholderIndex].hotType);
            searchDom.attr('data-id', hotobject[placeholderIndex].dataId);
            if (placeholderIndex >= hotobject.length - 1) {
                placeholderIndex = 0;
            } else {
                placeholderIndex += 1;
            }
        } else {
            clearInterval(placeholderTimer);
        }
    },8000);

    // 绑定手机号弹窗
    $(".get-phone").on("click", ".c-btn,.close,.phone-bg", function () {
        $(".get-phone").hide();
    });

    $('.show-input > span').click(function () {
        $('.show-input').hide();
        $('.nav').fadeIn(800);
        $('.click-seek').show();
    });

    //搜索
    $('#submit-search').on('click', function () {
        var $keyWorld = $(".header-search .txt").val();
        var $hotType = $(".header-search .txt").attr('hot-type');
        var $dataId = $(".header-search .txt").attr('data-id');
        var $placeholder = $(".header-search .txt").attr('placeholder');
        $keyWorld = $.trim($keyWorld);
        var identify = $('#search-identify').val();
        $keyWorld = $keyWorld.replace(/[<>&"]/g,function(c){return {'<':'','>':'','&':'','"':'',"'":'',"!":'',"</":'',"<script":'',"</script":'',"<!--":'',"-->":''}[c];});
        if ($keyWorld.length <= 0 && $placeholder == '输入课程关键词') {
            alert('请输入搜索关键词 ...');
            return false;
        }

        // 首先处理是否是直播广告
        var $liveId = $(".header-search .txt").attr('live-ad-id');
        if ($liveId * 1 > 0) {
            window.location.href = "/live/"+ $liveId + ".html?source=searchbox";
            return false;
        }

        // 没有输入关键词，且有滚动词条和非直播课程情况下，用滚动词条替换搜索关键词
        if ($keyWorld.length <= 0 && $hotType * 1 == 1) {
            $keyWorld = $placeholder.slice(3); // 去掉‘热搜：’提示
        }

        var pageType = $(this).attr('pageType');
        if (pageType * 1 == 2) {
            if ($hotType * 1 == 2 && $keyWorld.length <= 0) {
               window.location.href = '//' + window.location.host + '/live/' + $dataId + '.html?source=searchbox';
            } else {
               window.location.href = '//' + window.location.host + '/search/live?keyWorld=' + $keyWorld + '&identify=' + identify;
            }
        } else {
            if ($hotType * 1 == 2 && $keyWorld.length <= 0) {
               window.location.href = '//' + window.location.host + '/live/' + $dataId + '.html?source=searchbox';
            } else {
               window.location.href = '//' + window.location.host + '/search/video?keyWorld=' + $keyWorld + '&identify=' + identify;
            }
        }
    });

    $(".header-search .txt").keydown(function (event) {
        if (event.keyCode === 13) { //绑定回车
            $('#submit-search').click();
        }
    });

    //点击按钮统计
    $('.trigger-click-statistics').aliLoggerClick();

    // 导航栏高亮
    $('#new-header').find('.nav-list[data-index=' + Param.navRoute + ']').addClass('active');

    // 消息下拉 刷新
    $("#right-bar .news").on('mouseover', function () {
        var that = $(this);
        if (that.hasClass('hasLoading')) {
            return false;
        }
        if (Param.uid == 0) {
            that.find('.news-t-loading').addClass('hide');
            return false;
        }
        that.addClass('hasLoading');
        $.ajax({
            url: Url.noticePreview,
            method: 'get',
            xhrFields: {withCredentials: true},
            success: function (response) {
                that.find('.news-t-loading').addClass('hide');
                that.find('.news-t-container').html(response);
            },
            error: function (response) {
                return false;
            }
        });
    }).on('mouseout', function () {
        $(this).removeClass('active')
    });

    if (parseInt(Param.uid)) {
        (parseInt(Param.isLivePage) === 0) && liveDesktopNotification();
        // 未读消息统计
        $.ajax({
            url: Url.unreadNoticeCount,
            method: 'get',
            dataType: 'json',
            xhrFields: {withCredentials: true},
            success: function (resp) {
                $('#right-bar .news .num').toggleClass('hide', resp.count - 0 <= 0).html(resp.count);
            }
        })
    } else {
        $('#right-bar .news .num').addClass('hide');
    }

    if (parseInt(Param.returnVisiter_popup)) {
        returnUserCountDownTime(Param.returnVisiter_popup);
    }
    // 昨日注册次日回访用户优惠购活动
    function returnUserCountDownTime(endtime) {
        endtime = endtime + '000';
        window.setInterval(function () {
            var nowtime = (new Date()).valueOf();
            var time = endtime - nowtime;
            if (time > 0) {
                var hour = parseInt(time / 1000 / 60 / 60 % 24);
                var minute = parseInt(time / 1000 / 60 % 60);
                var seconds = parseInt(time / 1000 % 60);
            } else {
                var hour = minute = seconds = "00";
            }
            function PrefixInteger(num, length) {
                return (Array(length).join("0") + num).slice(-length);
            }
            hour = PrefixInteger(hour, 2);
            minute = PrefixInteger(minute, 2);
            seconds = PrefixInteger(seconds, 2);
            $('.tips-classify-pay-nav .h,.tips-classify-rcountdown .h').html(hour);
            $('.tips-classify-pay-nav .m,.tips-classify-rcountdown .m').html(minute);
            $('.tips-classify-pay-nav .s,.tips-classify-rcountdown .s').html(seconds);
        }, 1000);
    }

});


/**
 * 免费直播课全局浏览器提醒
 */
function liveDesktopNotification() {
    if (!window.Notification) {
        console.log('浏览器不支持通知');
        return false;
    }
    $.ajax({
        type: "get",
        url: Url.desktopNotificationUrl,
        dataType: "json",
        success: function (res) {
            if (res.status == 200) {
                var options = {
                    dir: "auto",
                    body: res.data.teacherName + '老师公开课火热直播中，戳这里进入！免费听 >',
                    requireInteraction: true,
                    icon: res.data.cover
                };
                var liveUrl = res.data.liveUrl;
                var title = '虎课免费公开课';
                // 检查用户曾经是否同意接受通知
                if (Notification.permission === 'granted') {
                    clickRecordLiving(709, res.data.id);
                    var notification = new Notification(title, options); // 显示通知
                    notification.onclick = function() {
                        clickRecordLiving(710, res.data.id)
                        if ((/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent))) {
                            location.href = liveUrl;
                        } else {
                            window.open(liveUrl);
                        }
                    };
                    notification.onclose = function() {
                        clickRecordLiving(711, res.data.id)
                        console.log('点击关闭浏览器提醒');
                    };
                } else if (Notification.permission === 'default') {
                    // 用户还未选择，可以询问用户是否同意发送通知
                    Notification.requestPermission(function(permission) {
                        // 如果用户同意，就可以向他们发送通知
                        if (permission === 'granted') {
                            clickRecordLiving(709, res.data.id);
                            var notification = new Notification(title, options); // 显示通知
                            notification.onclick = function() {
                                clickRecordLiving(710, res.data.id)
                                if ((/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent))) {
                                    location.href = liveUrl;
                                } else {
                                    window.open(liveUrl);
                                }
                            };
                            notification.onclose = function() {
                                clickRecordLiving(711, res.data.id)
                                console.log('点击关闭浏览器提醒');
                            };
                        } else if (permission === 'default') {
                            console.log('用户关闭授权，未刷新页面之前，可以再次请求授权');
                        } else {
                            console.log('用户拒绝授权，不能显示通知');
                        }
                    });
                } else {
                    console.log('用户曾经拒绝显示通知');
                }
            }
        }
    });
}

var bindPhoneWin = function(){
    hayer.confirm('<p class="mt15"><img style="height:80px" src="https://js.huke88.com/assets/revision/images/bind-icon2.png" alt=""></p><p class="fz16 c333 mt20">亲爱的虎课用户，为了您的账户安全以及响应国家政策</p><p class="fz16 c666 mt20">请绑定手机号后安全使用~</p><p class="mt20"></p>',
        {
            btn: ['立即绑定'],//按钮
            btnColor: ['2'] //按钮颜色 1白色 2黄色 3橙色 0不显示
        }, function () {
            window.open(Url.bindUrl);
            return false;
        }
    );
}

// 新版登录注册 2017-9-8
$(function () {

    if (Param.loginPop == 2) {
        //账号已在别处登录提示
        hayer.confirm('<p class="fz20-c3">小虎提醒</p><p class="fz16-c6">您的账号已在别处登录</p><p class="fz16-c6">如非本人操作请立即修改密码哦~</p>',
            {
                btn: [],//按钮
                btnColor: ['0'] //按钮颜色 1白色 2黄色 3橙色 0不显示
            }, function () {
                // 跳转连接
                return false;
            }
        );
        toLogin();
    } else if (Param.loginPop == 3) {
        var popHtml = '<div class="proving-phone-win"><div class="win-m"><div class="close">×</div><p class="p1">小虎提醒</p>';
        popHtml += '<p class="p2">登录太频繁可能导致封号哦~请验证通过后登录！</p><div class="phone-num"><input type="hidden" name="" value="' + Param.userPhone + '">';
        popHtml += '<i class="phone-icon"></i>' + Param.userPhone.substr(0, 3) + '****' + Param.userPhone.substr(-4) + '</div>';
        popHtml += '<div class="phone-code clearfix"><div class="code-l fl"><input type="text" name="" placeholder="请输入图形验证码"></div>';
        popHtml += '<div class="code-r fr"><img class="captchaimg" src="" alt="换一个" title="换一个" style="cursor:pointer"></div>';
        popHtml += '<div class="error-txt">图形验证码错误，请重新输入</div></div>';
        popHtml += '<div class="phone-yz"><div class="yz-l fl"><input type="text" name="code" placeholder="请输入验证码"></div>';
        popHtml += '<div class="yz-r fr"><input type="button" value="获取动态密码" class="get-p"></div><div class="error-txt">验证码错误，请重新输入</div></div>';
        popHtml += '<div class="phone-btn">登录</div></div></div>';
        $('body').append(popHtml);

        // 验证码发送60秒倒计时
        var countdown_valid = 60; //倒计时秒数
        function send_valide_mail() {
            var obj = $(".proving-phone-win .get-p");
            settime2(obj);
        }

        function settime2(obj) { //发送验证码倒计时
            if (countdown_valid == 0) {
                obj.removeClass("ed");
                obj.attr("disabled", false);
                obj.val("发送验证码");
                countdown_valid = 60;
                return;
            } else {
                obj.addClass("ed");
                obj.attr("disabled", true);
                obj.val(countdown_valid + "s");
                countdown_valid--;
            }
            setTimeout(function () {
                    settime2(obj)
                }
                , 1000)
        }

        $(".proving-phone-win .close").click(function () {
            location.reload();
        });
        // 点击发送验证码
        var getValideCodeAlready = false;
        $(".proving-phone-win .get-p").click(function () {
            var that = $(this);
            if (getValideCodeAlready) {
                return false;
            }
            getValideCodeAlready = true;
            // 点击发送验证码后验证手机号码格式
            var phone = $(this).parents('.win-m').find('.phone-num input').val();

            var verifyCode = that.parents('.win-m').find('.phone-code input').val();
            if (verifyCode == '') {
                that.parents('.win-m').find('.phone-code').addClass('error');
                that.parents('.win-m').find('.phone-code .error-txt').html('请输入图形验证码');
                getValideCodeAlready = false;
                return false;
            }

            $.ajaxSetup({async: false});
            $.ajax({
                type: "get",
                url: Url.sendMessage,
                data: {
                    phone: phone,
                    verifyCode: verifyCode
                },
                dataType: "json",
                success: function (data) {
                    if (data.state == 1) { // 发送成功
                        send_valide_mail();
                        that.parents('.win-m').find('.phone-code').removeClass('error');
                        getValideCodeAlready = false;
                    } else if (data.state == 2) { // 图形验证码错误
                        if (that.parents('.win-m').find('.phone-code').is(':hidden')) {
                            var text = '请输入图形验证码';

                            that.parents('.win-m').find('.captchaimg').click();
                        } else {
                            var text = '图形验证码错误，请重新输入';
                        }

                        that.parents('.win-m').find('.phone-code').show();
                        that.parents('.win-m').find('.phone-code').addClass('error');
                        that.parents('.win-m').find('.phone-code .error-txt').html(text);
                        getValideCodeAlready = false;
                    } else if (data.count == 5) {
                        that.parents('.win-m').find('.phone-yz').addClass('error');
                        that.parents('.win-m').find('.phone-yz .error-txt').html(data.msg);
                        getValideCodeAlready = true;
                    } else {
                        alert(data.msg);
                        getValideCodeAlready = false;
                    }
                },
                error: function () {
                    getValideCodeAlready = false;
                }
            });

        });

        // 点击切换验证码
        $(".proving-phone-win .captchaimg").click(function () {
            var unique = new Date().getTime();
            var that = $(this);
            $.get('/site/captcha', {'refresh': 1, 'v': unique}, function (data) {
                that.attr('src', data.url);
            });
        })
        $(".proving-phone-win .captchaimg").click();
        // 点击登录（或注册）
        $('.proving-phone-win .phone-btn').click(function () {
            var that = $(this);
            var data = {};
            data.phone = $(this).parents('.win-m').find('.phone-num input').val();
            data.code = $(this).parents('.win-m').find('.phone-yz .yz-l input').val();

            $.get(Url.phoneValide, data, function (res) {
                var resData = $.parseJSON(res);
                if (resData.state == 1) {
                    location.reload();
                } else {
                    alert('验证失败！');
                }
            })
        });
        $(".proving-phone-win .close").click(function () {
            $('.proving-phone-win').remove();
        });

    } else if (Param.loginPop == 4) {
        // 提醒绑定手机弹窗
        hayer.confirm('<p class="fz20-c3">小虎提醒</p><p class="fz16-c6">登录太频繁可能导致封号哦~请验证通过后登录！</p>',
            {
                btn: ['去绑定手机'],//按钮
                btnColor: ['2'], //按钮颜色 1白色 2黄色 3橙色
                cancel: function () {
                    location.reload();
                }
            }, function () {
                window.open(Url.bindUrl);
            }
        );
    } else if (Param.loginPop == 5) {
        // 提醒绑定手机弹窗
        hayer.confirm('<p class="fz20-c3">小虎提醒</p><p class="fz16-c6">您的账号近期频繁登录，今日已无法登录</p><p class="fz16-c6">建议您修改密码，明日再来学习！</p><p class="fz16-c6">如有疑问请联系客服：<a href="javascript:;" onclick="open_kefu()" class="qq-icon"></a></p>',
            {
                btn: [],//按钮
                btnColor: ['0'] //按钮颜色 1白色 2黄色 3橙色 0不显示
            }, function () {
                // 跳转连接
                return false;
            }
        );
    }

    // 前端校验手机号码
    function checkTelNum(mobile) {
        // var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
        var myreg = /^1[3456789]\d{9}$/;
        if (!myreg.test(mobile)) {
            return false;
        } else {
            return true;
        }
    }

    // *********************************  引导用户绑定手机号开始  *****************************************************
    if (typeof $('#bind-phone-new') != 'undefined' && $('#bind-phone-new').length > 0) {
        // 引导手机号绑定的图形验证码
        var _unique = new Date().getTime()
        var _csrf = $('meta[name="csrf-token"]').attr('content');
        $.get('/bind/captcha', {'refresh': 1, 'v': _unique}, function (data) {
            $('#bind-phone-new .win-m').find('.captchaimg-reduce').attr('src', data.url);
        });

        // 关闭弹窗 还你一个干净的弹窗！
        $('#bind-phone-new').find('.close').bind('click', function () {
            $('#bind-phone-new').addClass('hide');
            $('#bind-phone-new input[name=phone-new], #bind-phone-new input[name=code-new], #bind-phone-new input[name=sms-new]').val('');
            $('#bind-phone-new .phone-error, #bind-phone-new .code-error, #bind-phone-new .sms-error').addClass('hide');
        });

        /**
         * 绑定手机
         */
        $('#bind-phone-new input[name=bind-phone]').bind('click', function () {
            var $phone = $.trim($('#bind-phone-new input[name=phone-new]').val());
            var $phone_error = $('#bind-phone-new .phone-error');
            var $code = $.trim($('#bind-phone-new input[name=code-new]').val());
            var $code_error = $('#bind-phone-new .code-error');
            var $sms = $.trim($('#bind-phone-new input[name=sms-new]').val());
            var $sms_error = $('#bind-phone-new .sms-error');

            if ($phone == '' || !checkTelNum($phone)) {
                errorMessage($phone_error, true, '请输入正确的手机号码');
                return false;
            } else {
                errorMessage($phone_error, false);
            }

            if ($code == '' || $code.length != 4) {
                errorMessage($code_error, true, '请输入正确的图形验证码');
                return false;
            } else {
                errorMessage($code_error, false);
            }

            if ($sms == '' || $sms.length != 4) {
                errorMessage($sms_error, true, '请输入正确的短信验证码');
                setTimeout(function () {
                    errorMessage($sms_error, false);
                }, 3000)
                return false;
            } else {
                errorMessage($sms_error, false);
            }

            $.ajax({
                url: Url._bindPhone,
                type: 'POST',
                dataType: 'JSON',
                data: {
                    '_csrf-frontend': _csrf,
                    'phone': $phone,
                    'smsCode': $sms,
                    'verifyCode': $code
                },
                success: function (res) {
                    if (res.msg === 'noSmsCode' || res.msg === 'errorSms') {
                        errorMessage($sms_error, true, '请填写正确有效的短信验证码');
                        setTimeout(function () {
                            errorMessage($sms_error, false);
                        }, 3000);
                    } else if (res.msg === 'errorPhone') {
                        errorMessage($phone_error, true, '请填写正确的手机号码');
                    } else if (res.msg === 'errorCaptcha') {
                        errorMessage($code_error, true, '请填写正确的图形验证码');
                    } else if (res.msg === 'success') {
                        $('#bind-phone-new').remove();
                    }
                }
            })
        });

        /**
         * 发送短信验证码
         */
        $('#bind-phone-new input[name=sms-send]').bind('click', function () {
            var $phone = $.trim($('#bind-phone-new input[name=phone-new]').val());
            var $phone_error = $('#bind-phone-new .phone-error');
            var $code = $.trim($('#bind-phone-new input[name=code-new]').val());
            var $code_error = $('#bind-phone-new .code-error');
            var $sms_error = $('#bind-phone-new .sms-error');

            if ($phone == '' || !checkTelNum($phone)) {
                errorMessage($phone_error, true, '请输入正确的手机号码');
                return false;
            } else {
                errorMessage($phone_error, false);
            }

            if ($code == '' || $code.length != 4) {
                errorMessage($code_error, true, '请输入正确的图形验证码');
                return false;
            } else {
                errorMessage($code_error, false);
            }

            $.ajax({
                url: Url._sendMessageNew,
                type: 'POST',
                dateType: 'JSON',
                data: {'_csrf-frontend': _csrf, 'verifyCode': $code, 'phone': $phone, 'type': 1},
                success: function (res) {
                    var $res = $.parseJSON(res);

                    if ($res.state === 1) {
                        _clock($('#bind-phone-new input[name=sms-send]'));
                    } else if ($res.state === 2) {
                        errorMessage($code_error, true, $res.msg);
                    } else if ($res.state === 3) {
                        errorMessage($phone_error, true, $res.msg);
                    } else if ($res.state === 0) {
                        errorMessage($sms_error, true, $res.msg);
                        setTimeout(function () {
                            errorMessage($sms_error, false);
                        }, 3000);
                    } else if ($res.state === 4) {
                        errorMessage($sms_error, true, $res.msg);
                        setTimeout(function () {
                            errorMessage($sms_error, false);
                        }, 3000);
                    }
                }
            })
        });

        // 刷新图形验证码
        $('#bind-phone-new .win-m').find('.captchaimg-reduce').bind('click', function () {
            var $unique = new Date().getTime();
            var that = $(this);
            $.get('/bind/captcha', {'refresh': 1, 'v': $unique}, function (data) {
                that.attr('src', data.url);
            });
        });

        /**
         * 手机号码输入监听
         */
        $('#bind-phone-new input[name=phone-new]').bind('input propertychange', function () {
            var $phone = $.trim($(this).val());
            var $tip_dom = $('#bind-phone-new .phone-error');

            if ($phone.length == 11) {
                if (!checkTelNum($phone)) {
                    errorMessage($tip_dom, true, '请输入正确的手机号码');
                }
            } else {
                errorMessage($tip_dom, false);
            }
        });

        /**
         * 图形验证码输入监听
         */
        $('#bind-phone-new input[name=code-new]').bind('input propertychange', function () {
            var $code = $.trim($(this).val());
            var $tip_dom = $('#bind-phone-new .code-error');
            var $send_button = $('#bind-phone-new input[name=sms-send]');

            if ($code.length == 4) {
                $.post(Url._checkCaptchaNew, {'_csrf-frontend': _csrf, 'code': $code}, function (res) {
                    $res = $.parseJSON(res);

                    if ($res.msg === 'success') {
                        $send_button.removeClass('ed');
                        $send_button.attr('disabled', false);
                    } else {
                        errorMessage($tip_dom, true, '请输入正确的图形验证码');
                    }
                })
            } else {
                $send_button.addClass('ed');
                $send_button.attr('disabled', true);
                errorMessage($tip_dom, false);
            }
        });

        /**
         * 错误信息的展示和隐藏
         * @param _dom
         * @param _type
         * @param _message
         */
        function errorMessage(_dom, _type, _message) {
            if (_message !== '') {
                _dom.html(_message);
            }

            if (_type == true) {
                _dom.removeClass('hide');
            } else {
                _dom.addClass('hide');
            }
        };

        /**
         * 倒计时
         * @param obj
         * @private
         */
        function _clock(obj) {
            settime(obj)
        };
        // *********************************  引导用户绑定手机号结束  *****************************************************
    }

    var huke_share_sign = {
        'tag':'share_sign',
        bdText: '今日学习上上签，我是'+Param.username+'，我在虎课网学设计',
        bdDesc: '虎课网学设计 · 每天进步一点点',
        onBeforeClick:function(cmd, config){
            config.bdUrl = Param.share_img;
            config.bdPic = Param.share_img;
            return config;
        }
    };
    (function(){
        if( window._bd_share_config!==void 0 ){
            if( window._bd_share_config.share!==void 0 ){
                if( window._bd_share_config.share instanceof Array ){
                    var is_contain_sign = false;
                    for( var i=0; i<window._bd_share_config.share.length; i++ ){
                        if( window._bd_share_config.share[i].tag=='share_sign' ){
                            is_contain_sign = true;
                        }
                    }
                    if( is_contain_sign ){
                        window._bd_share_config.share.push(huke_share_sign);
                    }
                }else{
                    var share_tmp = window._bd_share_config.share;
                    window._bd_share_config.share = [];
                    window._bd_share_config.share.push(share_tmp);
                    window._bd_share_config.share.push(huke_share_sign);
                }
            }
        }else{
            window._bd_share_config = {};
            window._bd_share_config.share = [];
            window._bd_share_config.share.push(huke_share_sign);
        }
        with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = Url.ShareJs];
    })();

    var activityCookieCloseName = 'ACTIVITY_SMALL_CLOSE_COOKIE';


    if( Param.is_show_an2!=void 0 ){
        if( Param.is_show_an2==1 ){
            $(".sign-opt-mask,.act-prompt").show();
            $(".act-prompt .close").click(function(){
                $(".sign-opt-mask,.act-prompt").hide();
                $(".act-prompt-s").show();
            })
        }else{
            $(".act-prompt-s").show();
        }
        $(".act-prompt-s .close").click(function(){
            $(".act-prompt-s").hide();
        })
    }

    if (Param.is_show_double_twelve != void 0) {
        if (Param.is_show_double_twelve == 1) {
            $(".sign-opt-mask,.act-prompt-12").show();
            $(".act-prompt-12 .close").click(function () {
                $(".sign-opt-mask,.act-prompt-12").hide();
                $(".act-prompt-12-s").show();
            })
        } else {
            $(".act-prompt-12-s").show();
        }
        $(".act-prompt-12-s .close").click(function () {
            $(".act-prompt-12-s").hide();
        })
    }

    if (Param.is_show_newyear_study != void 0) {
        if (Param.is_show_newyear_study == 1) {
            $(".sign-opt-mask,.act-prompt-newyear-study").show();
            $(".act-prompt-newyear-study .close").click(function () {
                $(".sign-opt-mask,.act-prompt-newyear-study").hide();
                $(".act-prompt-newyear-study-s").show();
            })
        } else {
            $(".act-prompt-newyear-study-s").show();
        }
        $(".act-prompt-newyear-study-s .close").click(function () {
            $(".act-prompt-newyear-study-s").hide();
        })
    }


    if (Param.is_show_new_year != void 0) {
        if (Param.is_show_new_year == 1) {
            $(".sign-opt-mask,.act-prompt-new-year").show();
            $(".act-prompt-new-year .close").click(function () {
                $(".sign-opt-mask,.act-prompt-new-year").hide();
                $(".act-prompt-new-year-s").show();
            })
        } else {
            $(".act-prompt-new-year-s").show();
        }
        $(".act-prompt-new-year-s .close").click(function () {
            $(".act-prompt-new-year-s").hide();
        })
    }

    if (Param.is_show_summer_free != void 0) {
        if (Param.is_show_summer_free == 1) {
            $('.act-prompt-mask,.act-prompt-summer-free').show();
            $('.act-prompt-summer-free .close').click(function () {
                $('.act-prompt-mask,.act-prompt-summer-free').hide();
                $('.act-prompt-summer-free-s').removeClass('hide');
                $('.act-prompt-summer-free-s').show();
                $('.act-prompt-summer-free-left.close-left').removeClass('hide');
                $('.act-prompt-summer-free-left.close-left').show();
            })
        } else {
                $('.act-prompt-summer-free-s').show();
                $('.act-prompt-summer-free-left.close-left').show();
        }
        $('.act-prompt-summer-free-s .close').click(function () {
            $('.act-prompt-summer-free-s').hide();
            $('.act-prompt-summer-free-left').removeClass('hide');
            $('.act-prompt-summer-free-left').show();
        })
    }



    if (Param.is_show_labor_day != void 0) {
        if (Param.is_show_labor_day == 1) {
            $(".sign-opt-mask,.act-prompt-labor-class").show();
            $(".act-prompt-labor-class .close").click(function () {

                $(".sign-opt-mask,.act-prompt-labor-class").hide();
                $(".act-prompt-labor-small-class").show();
            })
        } else {

            if(Param.hasOwnProperty('isCoursePage') && Param.isCoursePage == 1){
                if($.cookie(activityCookieCloseName) !== '1'){
                    $(".act-prompt-labor-small-class").show();
                }
            }else{
                $(".act-prompt-labor-small-class").show();
            }

        }
        $(".act-prompt-labor-small-class .close").click(function () {
            if($.cookie(activityCookieCloseName) !== '1'){
                $.cookie(activityCookieCloseName, 1, {expires: Tools.zeroPoint(), path: '/'});
            }
            $(".act-prompt-labor-small-class").hide();
        })
    }

    if (Param.is_show_full_return != void 0) {
        if (Param.is_show_full_return == 1) {

            $(".act-prompt-mask,.act-prompt-full-return").show();
            $(".act-prompt-full-return .close").click(function () {

                $(".act-prompt-mask,.act-prompt-full-return").hide();
                $(".act-prompt-full-return-small").show();
            })
        } else {
            $(".act-prompt-full-return-small").show();
        }
        $(".act-prompt-full-return-small .close").click(function () {
            if($.cookie(activityCookieCloseName) !== '1'){
                $.cookie(activityCookieCloseName, 1, {expires: Tools.zeroPoint(), path: '/'});
            }
            $(".act-prompt-full-return-small").hide();
        })
    }

    if(Param.hasOwnProperty('activityInduceExpiredPage')){


        /**
         * 活动绑定事件
         */
        var acitivityExpired181127 = {

            init: function () {
                this.bind();
            },

            bind: function () {

                $(".renewHide .renewProp .dclose").click(function () {
                    $(".renewHide").addClass('hide');
                    $(".npfRenewLeft").removeClass('hide')
                });
                $(".renewHide .tipsBot label").click(function () {
                    $('.renewHide').addClass('hide');

                    $.post('/activity/ajax-set-expired-not-remind', {
                        not_remind: 1,
                        '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
                    }, function (res) { });
                });
                $(".npfRenewLeft .dclose").click(function () {
                    $(".npfRenewLeft").addClass('hide')
                });
            }
        }

        acitivityExpired181127.init();
    }

    if(Param.hasOwnProperty('activityTwoForOneExpire')){

        var activityTwoForOne = {
            init:function(){
                this.countDown(Param.activityTwoForOneExpire);
                this.event();
            },

            countDown: function(t){
                var starttime = t;
                setInterval(function () {
                    var nowtime = luckTime ? luckTime :(new Date()).valueOf();
                    var time = starttime - nowtime;
                    if (time > 0) {
                        var hour = parseInt(time / 1000 / 60 / 60 % 24);
                        var minute = parseInt(time / 1000 / 60 % 60);
                        var seconds = parseInt(time / 1000 % 60);
                    } else {
                        hour = minute = seconds = "00"
                    }
                    function PrefixInteger(num, length) {
                        return (Array(length).join("0") + num).slice(-length);
                    }
                    hour = PrefixInteger(hour, 2);
                    minute = PrefixInteger(minute, 2);
                    seconds = PrefixInteger(seconds, 2);
                    $('.allVipMain .allVipTime .timeAct').html("<i>" +  hour + "</i>" + "<em>小时</em>" + "<i>" +  minute + "</i>" + "<em>分</em>" + "<i>" +  seconds + "</i>" + "<em>秒</em>");
                    $('.smallVipMain .smallVipTime').html(  hour + ":" +  minute + ":" + seconds);
                }, 300);
            },

            // 事件
            event:function(){
                $(".allVipHide .allVipMain .dclosev1").click(function () {
                    $(".smallAllVipHide").removeClass('hide');
                    $(".allVipHide").addClass('hide');
                });

                $(".smallAllVipHide .dclosev1").click(function () {
                    $(".smallAllVipHide").hide();
                });
            }
        };
        activityTwoForOne.init();
    }



    if (Param.is_show_summer_feedback_day != void 0) {
        if (Param.is_show_summer_feedback_day == 1) {
            $(".sign-opt-mask,.act-prompt-summer-feedback-class").show();
            $(".act-prompt-summer-feedback-class .close").click(function () {
                $(".sign-opt-mask,.act-prompt-summer-feedback-class").hide();
                $(".act-prompt-summer-feedback-small-class").show();
            })
        } else {
            $(".act-prompt-summer-feedback-small-class").show();
        }
        $(".act-prompt-summer-feedback-small-class .close").click(function () {
            $(".act-prompt-summer-feedback-small-class").hide();
        })
    }

    if(Param.hasOwnProperty('bootCategoryUpgrade')){

        $(".alert-act .close").click(function(){
            $(".mask,.alert-act").addClass('hide');
            $(".alert-act-s").removeClass('hide');
        })

        $(".alert-act-s .close").click(function(){
            $(".alert-act-s").addClass('hide');
        })

        bootCategoryUpgradetimer(Param.bootCategoryUpgradeTime);

        //倒计时
        function bootCategoryUpgradetimer(intSeconds) {
            if(intSeconds > 3600){
                intSeconds = 3600;
            }

            if (intSeconds > 0) {
                m = Math.floor(intSeconds / 60);
                s = Math.floor(intSeconds) - (m * 60);
            }else{
                return false;
            }

            var t = setInterval(function () {
                s--;
                if (s < 0) {
                    s = 59;
                    m--;
                }
                if (m < 10) {
                    $(".go-act .m").html("0" + m);
                } else {
                    $(".go-act .m").html(m);
                }
                if (s < 10) {
                    $(".go-act .s").html("0" + s);
                } else {
                    $(".go-act .s").html(s);
                }
                if (m == 0 && s == 0) {
                    $(".go-act .h,.go-act .m,.go-act .s").html("00");
                    clearInterval(t);
                }
            }, 1000)
        }
    }
});

/**
 * 统计充值的方法
 * @param subtype
 */
function entrance(subtype) {
    $.ajax({
        type: "post",
        url: Url.entrance,
        data: {subtype: subtype, '_csrf-frontend': $('meta[name="csrf-token"]').attr('content'), uid: Param.uid},
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function (message) {
        }
    });

}

// 虎课币抵扣冻结的提示
function hukeGlodFrozenConfirm() {
    hayer.confirm('<p class="fz18 c333 mt24">虎课币不足</p><p class="fz16 c666 mt24">您有未完成的订单，未支付完成将暂时冻结虎课币</p><p class="fz16 c666 mt18"><span class="cff7">2</span>分钟，请<span class="cff7">2</span>分钟后再来购买</p>',
        {
            btn: ['我知道啦'],
            btnColor: ['2'],
            btn1: function () {
                hayer.closeAll();//关闭弹窗
            }
        }
    );
}

/**
 * 统计页面的按钮的点击
 * @param $button_type
 */
function buttonClickRecord($button_type) {
    var data = {
        'uid': Param.uid,
        'uv_id': Param.uv_id,
        'button_type': $button_type
    };

    $.ajax({
        url: Url.buttonClickRecordUrl,
        data: data,
        method: 'post',
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function () {
        }
    });
}

/**
 * 统计页面的按钮的点击
 * @param $button_type
 */
function activityStatistics($tn, $sn, $id, $id2) {
    var data = {
        'uid': Param.uid,
        'uv_id': Param.uv_id,
        'tn': $tn,
        'sn': $sn,
        'id': $id,
        'id2': $id2,
    };

    $.ajax({
        url: Url.activityStatisticsRecordUrl,
        data: data,
        method: 'post',
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function () {
        }
    });
}

/**
 * 作业评改点击记录 1免费提醒  2完成提醒
 * @param $type
 */
function taskButtonClickRecord($type, $this) {
    $this.closest('.task-tips').addClass('hide');
    var data = {
        'uid': Param.uid,
        'type': $type
    };

    $.ajax({
        url: Url.taskButtonClickRecordUrl,
        data: data,
        method: 'post',
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function () {
        }
    });
}

/**
 * 实战营首页nav点击记录
 * @param uid
 */
function saveAbNavClickRecord() {
    var data = {
        'uid': Param.uid,
    };
    $.ajax({
        url: Url.abNavClickRecordUrl,
        data: data,
        method: 'get',
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function () {
        }
    });
}

//直播点击统计
function clickRecordLiving(type, living_id) {
    var living_id = living_id || 0;
    $.ajax({
        type: 'POST',
        url: Url.ajaxLivingClick,
        dataType: 'json',
        data: {
            "living_id": living_id,
            "button_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":0,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//直播访问统计
function viewRecordLiving(type, living_id) {
    var living_id = living_id || 0;
    $.ajax({
        type: 'POST',
        url: Url.ajaxLivingView,
        dataType: 'json',
        data: {
            "living_id": living_id,
            "view_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":0,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//训练营点击统计
function clickRecordTraining(type, training_id) {
    var training_id = training_id || 0;
    $.ajax({
        type: 'POST',
        url: Url.ajaxTrainingClick,
        dataType: 'json',
        data: {
            "training_id": training_id,
            "button_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":0,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//训练营访问统计
function viewRecordTraining(type, training_id) {
    var training_id = training_id || 0;
    $.ajax({
        type: 'POST',
        url: Url.ajaxTrainingView,
        dataType: 'json',
        data: {
            "training_id": training_id,
            "view_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":0,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//网校点击统计
function clickRecordOnlineSchool(type) {
    $.ajax({
        type: 'POST',
        url: Url.onlineSchoolclick,
        dataType: 'json',
        data: {
            "button_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":3,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//网校访问统计
function viewRecordOnlineSchool(type) {
    $.ajax({
        type: 'POST',
        url: Url.onlineSchoolview,
        dataType: 'json',
        data: {
            "view_type": type,
            "uid":Param.uid,
            "uv":Param.uv_id,
            "client_type":3,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if (s.status !== 200) {
            }
        }
    });
};

//全站通付费弹窗关闭 2017-08-25
$("#expire-win .close").on('click', function () {
    $("#expire-win").hide();
});

// 回到顶部的JS
$("#go-top").click(function () {
    $('body,html').animate({scrollTop: 0}, 500)
});

/******************************************签到start******************************************/
//今日签到
var signClick = false;
$("#sign-win .btn-not-sign").on('click', function () {
    if (signClick) {
        return false;
    } else {
        signClick = true;
        setTimeout(function(){signClick = false;}, 5000);
    }

    $.ajax({
        url: Url.signToday,
        method: 'post',
        data: {
            uid: Param.uid,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function (response) {
            response = $.parseJSON(response);
            if (response.error == 0) {
                $(".btn-not-sign").addClass('hide');
                $(".btn-has-sign").removeClass('hide');
                $(".sing-m-main .sign-list .list").each(function (k, v) {
                    if ($(this).hasClass('on') && !$(this).hasClass('ed')) {
                        $(this).addClass('on ed');
                    }
                });

                var num = $(".sing-m-main .num").html();
                $(".sing-m-main .num").html('').html(parseInt(num) + 1);
                $("#new-header .sign-txt").html('已签');

                open_sign_share(response.gold);
                signClickRecord(1);
                //window.location.reload();
            }
        },
        error: function () {

        }
    });
});
/**
 * 打开签到成功分享页面
 */
function open_sign_share(gold){

    $('#sign_gold').text(gold);

    append_canvas();
    setTimeout(function(){
        Huke_Post(Url.getMotto, {}, function(s){
            $("#sign-win .sign-m .close").click();

            var monthsInEng = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            var date = new Date();
            $(".cont-day").text(date.getDate());
            $('.cont-month').text(monthsInEng[date.getMonth()]);
            $(".cont-year").text(date.getFullYear());

            $('.sign-opt .sign-opt-cont .cont-c').text(s.data.motto);
            $('.sign-opt .sign-opt-cont .connt-bright').text(s.data.author);

            $('.sign-opt-mask').show();
            $('.sign-opt').show();

            // screen_img('sign_share_card');
        });
    },1000);
}
/**
 * 追加截图canvas脚本
 */
function append_canvas(){
    if( $('#canvas_png_js').size()==0 ){
        $('body script').last().after('<script id="canvas_png_js" src="'+Url.canvas2pngUrl+'"><\/script><script id="canvasjs" src="'+Url.html2canvasUrl+'"><\/script>');
    }
}

/**
 * 进行canvas生成
 * 执行此函数前先执行append_canvas
 * @param id
 */
function screen_img(id){
    // 获取内容id
    var content = document.getElementById(id);

    html2canvas(content, {
        onrendered: function(canvas) {
            //添加属性
            canvas.setAttribute('id','thecanvas');
            //读取属性值
            // var value= canvas.getAttribute('id');
            var img = canvas.toDataURL();
            // saveimg(img);
        }
    });
}
/**
 * 上传到又拍云
 * @param img
 */
function saveimg(img){
    return false;
    var formHtml  = "<form id='save_share_pic' method='post' enctype='Multipart/form-data' class='hide'>" +
        "<input type='hidden' name='policy' value='"+Param.share_policy+"'>" +
        "<input type='hidden' name='signature' value='"+Param.share_signature+"'></form>";
    $('body').append(formHtml);
    var form=document.getElementById("save_share_pic");
    var formData = new FormData(form);
    formData.append("file",convertBase64UrlToBlob(img));
    $.ajax({
        url:Url.webUploaderApiUrl,
        type:'POST',
        data:formData,
        dataType:"text",
        processData : false,
        contentType : false,
        success: function(resonpse) {
            resonpse =  JSON.parse(resonpse);
            Param.share_img = Url.ypDomain+resonpse.url
            $('#save_share_pic').remove();
        },
        error:function(){
            console.log('false');
        }
    });
}

/**
 * 将以base64的图片url数据转换为Blob
 * @param urlData
 *        用url方式表示的base64图片数据
 */
function convertBase64UrlToBlob(urlData){

    var bytes=window.atob(urlData.split(',')[1]);        //去掉url的头，并转换为byte

    //处理异常,将ascii码小于0的转换为大于0
    var ab = new ArrayBuffer(bytes.length);
    var ia = new Uint8Array(ab);
    for (var i = 0; i < bytes.length; i++) {
        ia[i] = bytes.charCodeAt(i);
    }

    return new Blob( [ab] , {type : 'image/png'});
}
$(".sign-opt").click(function (evt) {
    evt.stopImmediatePropagation();
    return;
});
$('.sign-opt .sign-opt-close').click(function(){
    $('.sign-opt-mask').hide();
    $('.sign-opt').hide();
    location.reload();
});

//再次签到
$("#sign-win .btn-agagin-sign").on('click', function () {
    $(".failed").addClass('hide');
    $(".sing-m-main").removeClass('hide');

    getSignData();
});

function getSignData() {

    $.ajax({
        url: Url.sign,
        method: 'post',
        data: {
            uid: Param.uid,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function (response) {
            response = $.parseJSON(response);
            switch (response.code) {
                case 10001:
                case 10003:
                    $(".sing-m-main").removeClass('hide');
                    $(".sing-m-main .sign-list .list").each(function (k, v) {
                        if (k < response.data.days) {
                            $(this).addClass('on ed');
                        }
                        if (k == response.data.days) {
                            $(this).addClass('on');
                        }
                    });
                    $(".sing-m-main .num").html(response.data.days);
                    break;
                case 10002:
                    $(".sing-m-main").removeClass('hide');
                    $(".sing-m-main .sign-list .list").each(function (k, v) {
                        if (k < response.data.days) {
                            $(this).addClass('on ed');
                        }
                    });
                    $(".btn-not-sign").addClass('hide');
                    $(".btn-has-sign").removeClass('hide');
                    $(".sing-m-main .num").html(response.data.days);
                    $(".sign-action span").html(response.data.gold);
                    break;
                case 10004:
                    $(".last").removeClass('hide');
                    $(".last .num").html(response.data.days);
                    $(".sign-action span").html(response.data.gold);
                    break;
                case 20001:
                    $("#sign-win").addClass('hide');
                    toLogin();
                    break;
            }
        },
        error: function () {
            $(".failed-error").removeClass('hide');
        }
    });
}

// 点击签到关闭按钮
$("#sign-win .sign-m .close").on('click', function () {
    $('#sign-win').addClass('hide');
});

// 我知道了 签到点击关闭
$("#sign-win .sign-m .i-know").on('click', function () {
    $('#sign-win').addClass('hide');
});

// 点击页面空白处关闭按钮
$("#sign-win .sign-m .close").on('click', function () {
    $('#sign-win').addClass('hide');
});
/******************************************签到end******************************************/


/******************************************导航start******************************************/

$('.nav-live').on('mouseover', function(){
    var $container = $(".nav-live");
    if ($container.hasClass('hasLoading')) {
        return false;
    }
    $container.addClass('hasLoading');
    setTimeout(function(){
        $container.removeClass('hasLoading');
    },20000);

    $.get(Url.navSchool, {'isSupportWebp':Param.isSupportWebp}, function(response){
        if (response.error == 0) {
            $container.siblings('.top-con-live').html(response.data);
            $('#liveNavIdentify').find('.lazy').lazyload()
            // $('#new-header .top-con-live .hkwx-list .li').hover(function () {
            //     $(this).addClass('on').siblings().removeClass('on');
            //     var rtid = $(this).attr('data-id');
            //     $('#liveNavIdentify').find('.hkwx-rMain').addClass('hide');
            //     $('#liveNavIdentify').find('.school-nav-' + rtid).removeClass('hide');
            //     $('#liveNavIdentify').find('.school-nav-' + rtid + ' .lazy').lazyload();
            // });
        } else {

        }
    });
});

$('.nav-pa').on('mouseover', function(){
    var $container = $(".nav-pa");
    if ($container.hasClass('hasLoading')) {
        return false;
    }
    $container.addClass('hasLoading');
    setTimeout(function(){
        $container.removeClass('hasLoading');
    },20000);

    $.get(Url.navPa, {'isSupportWebp':Param.isSupportWebp}, function(response){
        if (response.error == 0) {
            $container.siblings('.top-con-pa').html(response.data);
        }
    }, 'json');
});

if(Param.vipGetWin){
    $(".get-vip-win").removeClass("hide");

}

$('.get-vip-win').on('click','.close',function(){
    $(".get-vip-win").addClass("hide");

    $.ajax({
        url:Param.AjaxIsGetVipWinUrl,
        method: 'post',
        dataType: 'json',
        data: {
            vip_win_type: Param.vipGetWin,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        xhrFields: {
            withCredentials: true
        },

        success: function (data) {
            if(data.code == 200){
                Param.vipGetWin=0;

            }
        }

    })
});

$(".user-avatar").on('mouseleave',function(){
    // 如果全站通vip提示框显示 就隐藏掉
    if(Param.vipGetWin){
        $(".get-vip-win").addClass("hide");

        $.ajax({
            url:Param.AjaxIsGetVipWinUrl,
            method: 'post',
            dataType: 'json',
            data: {
                vip_win_type: Param.vipGetWin,
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
            },
            xhrFields: {
                withCredentials: true
            },

            success: function (data) {
                if(data.code == 200){
                    Param.vipGetWin=0;
                }
            }

        })
    }
})
// 个人信息下拉 刷新
$(".user-nav-info").on('mousemove', function () {
    var $container = $(".user-nav-info");


    if (Param.isLogin == 0) {
        return false;
    }
    if ($container.hasClass('hasLoading')) {
        return false;
    }
    $.ajax({
        url: Url.personalDropDown,//-----
        method: 'post',
        dataType: 'json',
        data: {
            uid: Param.uid,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function () {
            $container.addClass('hasLoading');
        },
        success: function (response) {
            if (response.error !== 1) {

                $(".user-drop-loading").addClass('hide');

                $item = $("#new-header .user-drop");

                //开启
                $item.removeClass('hide');

                var signHtml = '';
                var isVipHtml = '';
                if (response.hasSign) {
                    signHtml = '<a href="javascript:void(0);" class="day-check-button fr sign-btn-sidebar ed" report-position-id="10002">已签到</a>';
                } else {
                    signHtml = '<a href="javascript:void(0);" class="day-check-button fr sign-btn-sidebar" onclick="pagePositionClick(489)" report-position-id="10002">签到</a>';
                }

                if (response.vip_identity == '') {
                    isVipHtml = '<a href="' + response.ordinary_user_url + '" target="_blank" onclick="pagePositionClick(676)" report-position-id="10006"><i class="p-icon"></i></a></div>';
                } else {
                    isVipHtml = '<i class="new-vip-icon ' + response.vip_identity + '"></i></div>';
                }

                var $user_i =
                    '<div class="user-i">' +
                    '<a href="' + response.ucenter + '" target="_blank" report-position-id="10003"><img src="' + response.avator + '"></a>' +
                    '<div class="user-r">' +
                    '<div class="user-t clearfix">' +
                    '<div class="fl user-name"><a href="' + response.ucenter + '" target="_blank" report-position-id="10004">' + response.name + '</a></div>' +

                    '<div class="fl user-icon clearfix">' +
                    '<a href="' + response.phone_url + '" target="_blank" onclick="pagePositionClick(675)" report-position-id="10005"><i class="' + response.phone_identity + '"></i></a>' +
                    isVipHtml +
                    // '<div class="fr quit"><a href="' + response.logout + '">退出</a></div>' +
                    signHtml +

                    '</div>' +
                    '<div class="user-id clearfix"><span>学号：' + response.id + '</span><span>虎课币：<a href="' + response.goldUrl + '" target="_blank" onclick="pagePositionClick(490)">' + response.gold + '</a></span></div>' +
                    '</div>' +
                    '</div>';

                var $discount = '';
                if (response.discount) {
                    $discount =

                        '<div class="yhj">' +
                        '     <a href="' + response.discountUrl + '" class="fr" target="_blank" report-position-id="10008">去使用>></a>' +
                        '     <a href="' + response.discountUrl + '" class="uyhj" target="_blank" report-position-id="10009">' + response.discountWord + '</a>' +
                        '</div>';
                }

                var $surplus = '';
                if (!response.is_vip) {
                    //##invite_free_60
                    if (typeof response.is_open_free_60 != 'undefined' && response.is_open_free_60) {
                        $surplus += '<div class="surplus clearfix"><span class="fl">总免费学习数：<i>' + response.TotalFree + '次</i></span><span class="fr">今日可免费学习数：<i>' + response.free + '次</i></span></div><a href="' + response.inviteUrl + '" target="_blank" class="get-free">获得更多免费学习次数</a>';
                    }
                    $surplus += '<div class="surplus    "><span>今日可<i>免费</i>学习教程' + response.free + '个</span><span>每日免费学习 1 个教程</span></div>';

                    // $surplus += '<div class="surplus">今日可学教程<span>' + response.free + '个</span></div>' +
                    //     '<div class="vip-info">' +
                    //     '<p>开通VIP可收获更有自信的自己</p>' +
                    //     '<p>视频和图文<span>无限观看</span></p>' +
                    //     '<p>素材和源文件<span>无限下载</span></p>' +
                    //     '</div>';
                }

                if (!response.isAllVip) {
                    $surplus += '';
                }

                var buttonHtml = '';
                var laborExists = false;
                var activityOldUser20201221 = false;
                var oldUser20201111 = false;
                var oldUser20200717 = false;
                var oldUser = false;

                if (response.button.name || (response.hasOwnProperty('userTierClass') && response.userTierClass != '') || Param.hasOwnProperty('activityOldUser20201212')||Param.hasOwnProperty('oldUser20201111') ||Param.hasOwnProperty('oldUser20200717') || Param.hasOwnProperty('oldUser')) {
                    if(Param.hasOwnProperty('oldUser20201111')) {
                        oldUser20201111 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.oldUser20201111.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1026)" report-position-id="10003"><img src="' + Param.oldUser20201111.dropPic + '"></a></div>';
                    }else if(Param.hasOwnProperty('activityOldUser20211015') ) {
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.activityOldUser20211015.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1116)" report-position-id="10003"><img src="' + Param.activityOldUser20211015.dropPic + '"></a></div>';
                    } else if(Param.hasOwnProperty('activityOldUser20211101') ) {
                        activityOldUser20201221 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.activityOldUser20211101.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1116)" report-position-id="10021"><img src="' + Param.activityOldUser20211101.dropPic + '"></a></div>';
                    } else if(Param.hasOwnProperty('activityOldUser20211201') ) {
                        activityOldUser20201221 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.activityOldUser20211201.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1116)" report-position-id="10021"><img src="' + Param.activityOldUser20211201.dropPic + '"></a></div>';
                    } else if(Param.hasOwnProperty('activityOldUser20220311') ) {
                        activityOldUser20201221 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.activityOldUser20220311.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1116)" report-position-id="10021"><img src="' + Param.activityOldUser20220311.dropPic + '"></a></div>';
                    }else if(Param.hasOwnProperty('activityOldUser20201221')) {
                        activityOldUser20201221 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.activityOldUser20201221.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1026)" report-position-id="10003"><img src="' + Param.activityOldUser20201221.dropPic + '"></a></div>';
                    }else if(Param.hasOwnProperty('oldUser20200717')) {
                        oldUser20200717 = true;
                        buttonHtml = '<div class="clearfix report-module" report-module-id="18"><a href="' + Param.oldUser20200717.dropSrc + '" target="_blank" class="fl myvip" onclick="buttonClickRecord(1026)" report-position-id="10003"><img src="' + Param.oldUser20200717.dropPic + '"></a></div>';

                    }else if(Param.hasOwnProperty('oldUser')){
                        oldUser = true;
                        buttonHtml =  '<div class="clearfix report-module" report-module-id="18"><a href="'+ Param.oldUser.dropSrc +'" target="_blank" class="fl myvip" onclick="buttonClickRecord(1026)" report-position-id="10003"><img src="'+ Param.oldUser.dropPic +'"></a></div>';
                    }else if(Param.hasOwnProperty('laborDayDropDownSrc') && Param.hasOwnProperty('laborDayDropDownUrl') && Param.laborDayDropDownSrc !== ''){
                        laborExists = true;
                        buttonHtml = '<div class="upviplabor upvip-usertier report-module" report-module-id="17"><a href="'+ Param.laborDayDropDownUrl +'" target="_blank" onclick="entrance(57);activityStatistics(\'LaborDay\', \'personDropUv\')" report-position-id="10006"><img src="'+ Param.laborDayDropDownSrc +'"></a></div>'
                    }else{
                        if (response.button.upgrade) {  //能升级的
                            if (response.isAllVip) {
                                buttonHtml = '<div class="upvip"><a href="' + response.button.url + '"target="_blank" onclick="entrance(57);buttonClickRecord(70);"  report-position-id="10011"><img src="//js.huke88.com/assets/revision/images/upvip2.png"></a></div>'
                            } else {
                                buttonHtml = '<div class="vip-btn"><a href="' + response.button.url + '" target="_blank" onclick="entrance(57);buttonClickRecord(70);" report-position-id="10012">' + response.button.name + '</a></div>';
                            }
                        } else {    //不能升级的
                            buttonHtml = '<div class="vip-btn"><a href="' + response.button.url + '" target="_blank" onclick="entrance(2);buttonClickRecord(153);" report-position-id="10012">' + response.button.name + '</a></div>'
                        }
                    }
                }

                ////2021 0311~0411终身vip设计大赛广告位
                if(Param.hasOwnProperty('webActiveMxpsjdsSrc') && Param.hasOwnProperty('webActiveMxpsjdsUrl') && Param.webActiveMxpsjdsSrc !== ''){
                    laborExists = true;
                    buttonHtml = '<div class="upviplabor upvip-usertier"><a href="'+ Param.webActiveMxpsjdsUrl +'" target="_blank" onclick="entrance(57);activityStatistics(\'LaborDay\', \'personDropUv\')"><img src="'+ Param.webActiveMxpsjdsSrc +'"></a></div>'
                }

                buttonHtml += '<div class="spare-parts clearfix">';
                var downClickIds = [492, 491, 493, 677];
                var downClickPositionIds = [10013, 10014, 10015, 10016];
                $.each(response.down,function (k,v) {
                    buttonHtml += '<a href="' + v.url + '" target="_blank" class="fl '+ v.cssClass+'" onclick="pagePositionClick('+ downClickIds[k]+')" report-position-id="'+ downClickPositionIds[k] +'">' +
                    '<span></span>' +
                    '<p>' + v.name + '</p>' +
                    '</a>';
                })
                buttonHtml +=  '</div>';

                var pugcHtml = '';

                var groupVipInfo = '';

                if(response.hasOwnProperty('downEnterprise')){
                    groupVipInfo =    '<div class="group-vip-info"><a href="'+ response.downEnterprise.url +'" target="_blank" report-position-id="10018"><i class="home-icon"></i>企业主页</a><a href="'+ response.downEnterprise.memberUrl +'" target="_blank" report-position-id="10019"><i class="user-icon"></i>成员管理</a></div>';
                }
                var aLinkPugc= '<a report-position-id="10024" class="a-link-pugc" href="https://huke88.com/pugc" target="_blank"><span class="s1"></span><span class="s2">讲师入驻</span><span class="s3">申请成为讲师 瓜分30万现金</span></a>';
                var userWorkInfo = '<a class="user-work-info" href="https://huke88.com/teacher-opus/upload-works" target="_blank" report-position-id="10020"><span class="s1"></span><span class="s2">作品上传</span><span class="s3">向同学们展示你的作品</span></a>';

                if(response.button.name == false){
                    var userVipInfo = '';
                }else{
                    var userVipInfo = '<a class="user-vip-info" href="https://huke88.com/vip/category?tab=3" onclick="pagePositionClick(728)" report-position-id="10021" target="_blank"><span class="s1"></span><span class="s2">VIP特权</span><span class="s3">无限学习全站'+Param.videoNumber+'+教程，低至1.1元/天</span></a>';
                }


                if(response.flag == 1){
                    var userFlag = '<div class="report-module" report-module-id="60"><a class="user-flag flag-click-identify" href="javascript:;" report-position-id="10001"><span class="s1"></span><span class="s2">学习flag</span><span class="s3">2022开启快乐学习<i></i></span></a></div>';
                }else{
                    var userFlag = '<a class="user-vip-download" href="https://huke88.com/app" onclick="pagePositionClick(727)" target="_blank" report-position-id="10022"><span class="s1"></span><span class="s2">APP下载</span><span class="s3">离线缓存视频 随时随地观看</span></a>';
                }

                var userSetting = '<div class="user-bottom">' +
                    '<a href="' + response.logout + '" class="fr" onclick="pagePositionClick(678)" report-position-id="10023">退出</a>' +
                    '<a href="' + response.setting + '" target="_blank" onclick="pagePositionClick(497)" report-position-id="10024"><span></span>账户设置</a>' +
                    '</div>';

                if(laborExists || activityOldUser20201221 || oldUser20200717 || oldUser20201111 || oldUser){
                    $item.html($user_i + $discount + buttonHtml + pugcHtml + groupVipInfo + aLinkPugc + userWorkInfo + userVipInfo + userFlag + userSetting);
                }else{
                    $item.html($user_i + $discount + $surplus + buttonHtml+ pugcHtml + groupVipInfo + aLinkPugc + userWorkInfo + userVipInfo + userFlag + userSetting);
                }

            } else {
                return false;
            }
        },
        error: function (response) {
            return false;
        }
    });

    return false
});

 /**
  * flag活动
  * @type {{init: activityFlag.init, clickClass: activityFlag.clickClass, submit: activityFlag.submit, getPopup: activityFlag.getPopup, close: activityFlag.close}}
  */
 var activityFlag = {
    init:function () {
        this.getPopup();
        this.close();
        this.clickClass();
        this.changeModify();
        this.cancel();
        this.submit();
    },
    classValue:[],
    submitIdentify:1,
    data: {
        container: $(".act-2022flag"),
    },
    getPopup: function () {
        var $activityFLag = this;
        $("body").on('click', '.flag-click-identify', function(){
            $activityFLag.ajaxGetPopup(0);
        });
    },

    ajaxGetPopup: function(update){
        var $this = this;
        $.ajax({
            url: Url.activityFlag,
            method: 'post',
            dataType: 'json',
            data:{'_csrf-frontend': $('meta[name="csrf-token"]').attr('content'), update: update},
            success: function (response) {
                if(response.status === 200){
                    $this.classValue = [];
                    $(".act-2022flag").html(response.data.html).removeClass('hide');
                    if(update === 1){
                        $.each($this.data.container.find('.flag-popup1 .cont span.active'), function (k, v) {
                            var index = $(this).data('id');
                            $this.classValue.push(index);
                        })
                    }
                }
            },
        });
    },

    close: function () {
        var $this = this;
        $this.data.container.on('click','.flag-popup .close', function () {
            $(this).parent('.flag-popup').addClass('hide');
            $this.data.container.addClass('hide');
        });
    },

    clickClass: function () {
        var $this = this;
        $this.data.container.on('click','.flag-popup1 .cont span', function () {
            var index = $(this).data('id');
            var arrIndex = $.inArray(index,$this.classValue);
            if (arrIndex === -1) {
                if ($this.classValue.length >= 3) {
                    layer.msg('最多选择3个');
                    return false
                }
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                } else {
                    $(this).addClass('active');
                }
                $this.classValue.push(index);
            } else {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                } else {
                    $(this).addClass('active');
                }
                $this.classValue.splice(arrIndex,1)
            }
        });
    },

     changeModify: function () {
         var $this = this;
         $this.data.container.on('click','.flag-popup2 .cont2 .a-mod', function () {
             if($(this).data('status') === 0){
                 layer.msg($(this).data('error-message'));
                 return false;
             }
             $this.ajaxGetPopup(1);
             // $(this).parents('.flag-popup').addClass('hide');
             // $('.act-2022flag .flag-popup1').removeClass('hide');
         });
     },

     cancel: function () {
         var $this = this;
         $this.data.container.on('click','.flag-popup .a-cancel', function () {
             $this.ajaxGetPopup(0);
             // $(this).parents('.flag-popup').addClass('hide');
             // $('.act-2022flag .flag-popup2').removeClass('hide');
         });
     },

     ajaxSubmit: function(update){
        var $this = this;
         if($this.submitIdentify == 0){
             return false;
         }
         $this.submitIdentify = 0;
         $.ajax({
             url: Url.activityCreateFlag,
             method: 'post',
             dataType: 'json',
             data:{
                 index: $this.classValue,
                 update:update,
                 '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
             },
             success: function (response) {
                 $this.submitIdentify = 1;
                 if(response.status == 200){
                     $this.ajaxGetPopup(0);
                 }else{
                     layer.msg(response.msg);
                 }
             },
         });
     },

     submit:function () {
        var $this = this;
         $this.data.container.on('click', '.flag-popup1 .a-open', function () {
            $this.ajaxSubmit(0);
        });

         $this.data.container.on('click', '.flag-popup1 .a-modify', function () {
            if (!$this.classValue.length) {
                layer.msg('不能为空哦');
                return false
            }
            var text = '';
            $('.flag-popup1 .cont span.active').each(function () {
                text = text + $(this).text() + ' '
            });
            $('.act-2022flag .tips-popup .span').text(text);
            $(this).parents('.flag-popup').addClass('hide');
            $('.act-2022flag .tips-popup').removeClass('hide');
        });

         $this.data.container.on('click', '.tips-popup .btn1', function () {
            $('.act-2022flag .flag-popup1').removeClass('hide');
            $('.act-2022flag .tips-popup').addClass('hide');
        });

         $this.data.container.on('click', '.tips-popup .btn2', function () {
             $this.ajaxSubmit(1);
            // $('.act-2022flag .flag-popup1,.act-2022flag .tips-popup').addClass('hide');
            // $('.act-2022flag .flag-popup2').removeClass('hide');
        });
    }
};
 activityFlag.init();




//网校动态已读
function DynamicsReadLiveMessages(m_id,lid){
    window.open('http://huke88.com/live/' + lid + '.html','_blank');
}

//课程动态已读
function DynamicsReadCourseMessages(m_id,vid){
    window.open('http://huke88.com/course/' + vid + '.html','_blank');
}

//动态下拉
var course_page = 0;
var course_count_page = 1;

$(".dynamics").on('mousemove', function (){
    if(Param.isLogin == 0){
        return false;
    }
    //dynamicsCourseMessages();
});

function dynamicsCourseMessages(){
    var $container = $(".dynamics-course");

    if ($container.hasClass('hasLoading')) {
        return false;
    }
    $('.dynamics .dynamics-loading').removeClass('hide');
    $('.dynamics .dynamics-container').addClass('hide');
    if(course_count_page == course_page){
        return false;
    }
    var page = parseInt(course_page) + 1;
    $.ajax({
        url: Url.DynamicsCourseMessages,
        method: 'get',
        dataType: 'json',
        data: {
            page: page,
        },
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function () {
            $container.addClass('hasLoading');
        },
        success: function (response) {
            $('.dynamics .dynamics-container').removeClass('hide');
            $('.dynamics .dynamics-loading').addClass('hide');

            if(response.code == 200){
                if(response.data.count.length  == 0){
                    $('#new-header .dynamics .dynamics-course .con-null').removeClass('hide');
                    return false;
                }else{
                    var commentIHtml = '';
                    $.each(response.data.count.videos, function (k, v) {
                        commentIHtml += '<a class="list clearfix" user_action_type="statistics" user_action_explain="课程动态教程" user_action_id="26" target="_blank" href="https://huke88.com/course/' + v.id + '.html">';
                        commentIHtml += '<div class="user-avatar">' +
                            '                                        <img src="' + v.avator + '!/fw/100/format/jpg"' +
                            '                                             data-original=""' +
                            '                                             class="lazy">' +
                            '                                    </div>' +
                            '                                    <dl>' +
                            '                                        <dt class="title">' + v.title + '</dt>' +
                            '                                        <dt><span>' + v.name + '</span> <span>'+ v.dates +'</span></dt>' +
                            '                                    </dl>' +
                            '                                    <div class="right-img">' +
                            '                                        <img src="' + v.image_url + Param.addSupportWebpDynamics + '"' +
                            '                                             data-original=""' +
                            '                                             class="lazy">' +
                            '                                        <span class="play-cover"></span>' +
                            '                                    </div>' +
                            '                                </a>';
                    });

                    $(".dynamics .dynamics-span").html('动态');
                    course_page = response.data.count.page;
                    course_count_page = response.data.count.countPage;
                    $('#new-header .dynamics .dynamics-course').find(".list-c").append(commentIHtml);
                }
            }else {
                return false;
            }
        },
        error: function (response) {
            return false;
        }
    });

    return false
};


$('#new-header .dynamics .dynamics-t .nav2').click(function () {
    dynamicsLiveMessages();
});

var live_page = 0;
var live_count_page = 1;

function dynamicsLiveMessages(){
    var $container = $(".dynamics-live");

    if(live_count_page == live_page){
        return false;
    }

    var page = parseInt(live_page) + 1;

    if ($container.hasClass('hasLoading')) {
        return false;
    }

    $('.dynamics .dynamics-loading').removeClass('hide');
    $('.dynamics .dynamics-container').addClass('hide');

    $.ajax({
        url: Url.DynamicsLiveMessages,
        method: 'get',
        dataType: 'json',
        data: {
            page: page,
        },
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function () {
            $container.addClass('hasLoading');
        },
        success: function (response) {
            $('.dynamics .dynamics-loading').addClass('hide');
            $('.dynamics .dynamics-container').removeClass('hide');

            if(response.code == 200){
                if(response.data.count.length == 0){
                    $('#new-header .dynamics .dynamics-live .con-null').removeClass('hide');
                    return false;
                }else{
                    var commentIHtml = '';
                    var livecommentIHtml = '';
                    $.each(response.data.count.lives, function (k, v) {

                        if(v.liveStatus == '正在直播中'){
                            livecommentIHtml += '<a class="list clearfix" user_action_type="statistics" user_action_explain="网校动态教程" user_action_id="27" target="_blank" href="https://huke88.com/live/' + v.catalogId + '.html">';

                            if(v.is_read != 1){
                                livecommentIHtml += '<i class="dian"></i>';
                            }
                            livecommentIHtml += '<div class="user-avatar">' +
                                '                                        <img src="' + v.oneTeacherAvator + '"' +
                                '                                             data-original=""' +
                                '                                             class="lazy">' +
                                '                                    </div>' +
                                '                                    <dl>' +
                                '                                        <dt class="title">' + v.liveTitle + '</dt>';

                            if(v.twoTeacher.length == 0){
                                livecommentIHtml += '<dt><span>' + v.oneTeacher +'</span> <span class="';
                                if(v.liveStatus == '正在直播中'){
                                    livecommentIHtml += 'blue';
                                }
                                livecommentIHtml += '">'+ v.liveStatus +'</span></dt>';
                            }else{
                                livecommentIHtml += '<dt><span>' + v.oneTeacher + '&' + v.twoTeacher +'</span> <span class="';
                                if(v.liveStatus == '正在直播中'){
                                    livecommentIHtml += 'blue';
                                }
                                livecommentIHtml += '">'+ v.liveStatus +'</span></dt>';
                            }

                            livecommentIHtml += '</dl>' +
                                '                                    <div class="right-img">' +
                                '                                        <img src="' + v.detailCover  + Param.addSupportWebpDynamics + '"' +
                                '                                             data-original=""' +
                                '                                             class="lazy">' +
                                '                                        <span class="play-cover"></span>' +
                                '                                    </div>' +
                                '                                </a>';

                        }else{
                            commentIHtml += '<a class="list clearfix" user_action_type="statistics" user_action_explain="网校动态教程" user_action_id="27" target="_blank" href="https://huke88.com/live/' + v.catalogId + '.html" >';

                            if(v.is_read != 1){
                                commentIHtml += '<i class="dian"></i>';
                            }
                            commentIHtml += '<div class="user-avatar">' +
                                '                                        <img src="' + v.oneTeacherAvator + '"' +
                                '                                             data-original=""' +
                                '                                             class="lazy">' +
                                '                                    </div>' +
                                '                                    <dl>' +
                                '                                        <dt class="title">' + v.liveTitle + '</dt>';

                            if(v.twoTeacher.length == 0){
                                commentIHtml += '<dt><span>' + v.oneTeacher +'</span> <span class="';
                                if(v.liveStatus == '正在直播中'){
                                    commentIHtml += 'blue';
                                }
                                commentIHtml += '">'+ v.liveStatus +'</span></dt>';
                            }else{
                                commentIHtml += '<dt><span>' + v.oneTeacher + '&' + v.twoTeacher +'</span> <span class="';
                                if(v.liveStatus == '正在直播中'){
                                    commentIHtml += 'blue';
                                }
                                commentIHtml += '">'+ v.liveStatus +'</span></dt>';
                            }

                            commentIHtml += '</dl>' +
                                '                                    <div class="right-img">' +
                                '                                        <img src="' + v.detailCover  + Param.addSupportWebpDynamics + '"' +
                                '                                             data-original=""' +
                                '                                             class="lazy">' +
                                '                                        <span class="play-cover"></span>' +
                                '                                    </div>' +
                                '                                </a>';

                        }
                    });

                    live_page = response.data.count.page;
                    live_count_page = response.data.count.countPage;
                    $('#new-header .dynamics .dynamics-live').find(".list-c").append(livecommentIHtml);
                    $('#new-header .dynamics .dynamics-live').find(".list-c").append(commentIHtml);
                }
            }else {
                return false;
            }
        },
        error: function (response) {
            return false;
        }
    });

    return false
};

//动态类型
var dynamics_type = 0;

$('#new-header .dynamics .dynamics-t span').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    var index = $(this).index();
    dynamics_type = index;
    $('#new-header .dynamics .dynamics-con').addClass('hide');
    $('#new-header .dynamics .dynamics-con').eq(index).removeClass('hide');
});



//navGetDynamicsNotReadTotal();
//动态消息数量
function navGetDynamicsNotReadTotal() {
    $numbers = $(".dynamics .dynamics-span");
    if ($numbers.hasClass('hasRead')) {
        return false;
    }

    if (Param.isLogin == 0) {
        return false;
    }

    $.ajax({
        url: Url.DynamicsMessageCount,
        method: 'post',
        dataType: 'json',
        data: {
            uid: Param.uid,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function () {
            $numbers.addClass('hasRead');
        },
        success: function (response) {

            if (response.code == 200) {
                var count = parseInt(response.data.count);

                var showNum = '';
                if (count > 99) {
                    $numbers.html('动态<i>99+</i>');
                } else if (count <= 0 ) {

                } else {
                    $numbers.html('动态<i>'+count+'</i>');
                }
            }
        }
    })
}

//动态登陆
$('.login-tip').click(function () {
    toLogin();
});

//学习记录
$("#right-bar .study-log").on('mousemove', function (){
    var box = $('#right-bar .record-box');
    if(Param.isLogin == 0){
        box.addClass('hide');
        return false;
    }
    var $container = $(".record-box");

    if ($container.hasClass('hasLoading')) {
        return false;
    }

    box.find('.user-record-loading').removeClass('hide');

    $.ajax({
        url: Url.UserRecordList,
        method: 'get',
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        beforeSend: function () {
            $container.addClass('hasLoading');
        },
        success: function (response) {
            if(response.error === 0 ){
                if(response.limitCourse.length == 0){
                    box.find('.user-record-loading').addClass('hide');
                    box.find('.con-null').removeClass('hide');
                    return  false;
                }

                var todayHtml = '';
                var yesterdayHtml = '';
                var agoHtml = '';
                $.each(response.limitCourse, function (k, v) {
                    var date1 = new Date(parseInt(v.updated_at)*1000);
                    var perent = v.percent
                    if(isTime(date1) == 1){
                        todayHtml += '<div class="record-list">' +
                            '<a href="' + v.url + '" class="img" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank"><img src="https://pic.huke88.com/' + v.image_url + Param.addSupportWebpRecord + '" alt=""></a>' +
                            '<div class="img-r">' +
                            '<a href="' + v.url + '" class="title" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank">' + v.title + '</a>' +
                            '<div class="status"><span>' + perent.replace('已学至', '已学') + '</span><span>今日' + date1.getHours() +':'+ date1.getMinutes() + '</span></div>' +
                            '</div>' +
                            '</div>';
                    }else if(isTime(date1) == 2){
                        yesterdayHtml += '<div class="record-list">' +
                            '<a href="' + v.url + '" class="img" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank"><img src="https://pic.huke88.com/' + v.image_url + Param.addSupportWebpRecord + '" alt=""></a>' +
                            '<div class="img-r">' +
                            '<a href="' + v.url + '" class="title" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank">' + v.title + '</a>' +
                            '<div class="status"><span>' + perent.replace('已学至', '已学') + '</span><span>昨日' + date1.getHours() + ':' + date1.getMinutes() + '</span></div>' +
                            '</div>' +
                            '</div>';
                    }else {
                        agoHtml += '<div class="record-list">' +
                            '<a href="' + v.url + '" class="img" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank"><img src="https://pic.huke88.com/' + v.image_url + Param.addSupportWebpRecord + '" alt=""></a>' +
                            '<div class="img-r">' +
                            '<a href="' + v.url + '" class="title" user_action_type="statistics" user_action_explain="课程" user_action_id="32" target="_blank">' + v.title + '</a>' +
                            '<div class="status"><span>' + perent.replace('已学至', '已学') + '</span><span>'+ (parseInt(date1.getMonth())+1) +'-'+ date1.getDate()+' ' + date1.getHours() +':'+ date1.getMinutes() + '</span></div>' +
                            '</div>' +
                            '</div>';
                    }
                });

                box.find('.today').after(todayHtml);
                box.find('.yesterday').after(yesterdayHtml);
                box.find('.ago').after(agoHtml);

                box.find('.user-record-loading').addClass('hide');

                if(todayHtml == ''){
                    box.find('.today').addClass('hide');
                }else{
                    box.find('.today').removeClass('hide');
                }

                if(yesterdayHtml == ''){
                    box.find('.yesterday').addClass('hide');
                }else{
                    box.find('.yesterday').removeClass('hide');
                }

                if(agoHtml == ''){
                    box.find('.ago').addClass('hide');
                }else{
                    box.find('.ago').removeClass('hide');
                }
            }else {
                return false;
            }
        },
        error: function (response) {
            return false;
        }
    });
});

//头部固定
var animateFlag = 1;
$(document).scroll(function () {
    var scrollTop = $(document).scrollTop();
    if (scrollTop > 60) {
        $("#header").addClass('header-fixed');
        if (animateFlag) {
            animateFlag = 0;
            $("#header").stop().animate({
                'top': '0px'
            }, 500);
        }
    } else {
        if (animateFlag == 0) {
            animateFlag = 1;
            $("#header").removeClass('header-fixed');
            $("#header").animate({
                'top': '-60px'
            }, 500);
        }
    }
});


var _hmq = _hmq || [];

function load() {
    $('div.nav-banner div.img').each(function (k, v) {
        if (k !== 0) {
            var address = $(v).attr('data-address');
            var style = "background: url(" + address + ") no-repeat  center;background-size: cover";
            $(v).removeAttr('style').attr('style', style);
        }
    });
    function stopPropagation(e) {
        if (e.stopPropagation) {
            e.stopPropagation();
        } else {
            e.cancelBubble = false;
        }
    }

    var btn = $(".user-drop");
    var layer = $("#sign-win");
    btn.on('click', '.sign-btn-sidebar', function (e) {
        if (Param.uid == 0) {
            toLogin();
            return false;
        }

        layer.removeClass('hide');

        getSignData();
        stopPropagation(e);
    });

    window.onclick = function (e) {
        e = e || event;
        if (!$(".sign-m").is(e.target) && $(".sign-m").has(e.target).length === 0) {
            layer.addClass('hide');
        }

    };

    $("#slide-box").slide({
        mainCell: ".bd ul",
        autoPlay: true,
        // trigger: "click",
        interTime: 4000
    });

    $(window).scroll(function () {
        if ($(window).scrollTop() > $(window).height()) {
            $('#go-top').removeClass('hide');
        } else {
            $('#go-top').addClass('hide');
        }
    });

    //统计代码放到业务代码之后
    //低版本浏览器提示
    (function () {

        function getBrowserNoticeDomNew() {
            if ($(document).hasClass('upbrower')) {
                return false;
            }
            $.ajax({
                url: Url.getBrowserNoticeDom,
                type: 'get',
                dataType: 'jsonp',
                jsonp: "callback",
                success: function (response) {
                    $('body').append(response.html);
                    $(document).on('click', '.upbrower .close', function () {
                        $('.upbrower').addClass('hide')
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log(XMLHttpRequest.status);
                    console.log(XMLHttpRequest.readyState);
                    console.log(textStatus);
                }
            })
        }

        var b_name = navigator.appName;
        var b_version = navigator.appVersion;
        var version = b_version.split(";");
        if (b_name == "Microsoft Internet Explorer") {
            var trim_version = version[1].replace(/[ ]/g, "");
            /*如果是IE6或者IE7*/
            if (trim_version == "MSIE7.0" || trim_version == "MSIE6.0" || trim_version == "MSIE8.0" || trim_version == "MSIE9.0" || trim_version == "MSIE10.0") {
                getBrowserNoticeDomNew();
            }
        }
    })();

    //handata
    var handata = $('#handata_uid');
    var uid = handata.attr('bind-data-uid');
    var is_pay = handata.attr('bind-data-payUser');
    _hmq.push(['_uid', uid]);
    _hmq.push(['_is_pay', is_pay]);
    (function () {
        var stat = document.createElement('script');
        stat.type = 'text/javascript';
        stat.async = true;
        stat.src = 'https://stats.hanmaker.com/stats.js?v=2.0';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(stat, s);
    })();


    (function () {
        //百度统计代码
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?a0e66ced62f1926ee48b5f059ad9f039";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    })();
}


/**
 * 视频分类统计
 * @param video_id 视频id
 * @param type     存储类型（记录ippvuv时=1，其余为0）
 * @param field    当type为0时，记录的键值
 */
function videoClassificationStatistics(id, field, videoOrTag, type) {

    $.ajax({
        type: "post",
        url: Url.videoClassificationStatistics,
        data: {
            id: id,
            type: type,
            field: field,
            uv: Param.uv_id,
            videoOrTag: videoOrTag,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function (message) {
        }
    });
}


/*
 * 训练营站内入口统计
 * @param 主键 bannerId
 * @return null
 */
function trainingClickStatistics(bannerId) {

    $.ajax({
        url: Url.trainingAdStatistics,
        dataType: 'Json',
        method: 'Post',
        data: {
            'id': bannerId
        },
        success: function ($res) {
        }
    });
}
// 头部导航悬浮
function fixed() {
    var scrollTop = $(document).scrollTop();
    if (scrollTop > 60) {
        $("#new-header").addClass('header-fixed');
        $('#body-container').css('padding-top', '60px');
        if($('.guide-bottom').length && !$('.guide-bottom').hasClass('ishow')){
            $('.guide-bottom').addClass('ishow')
        }

    } else {
        $("#new-header").removeClass('header-fixed');
        $('#body-container').css('padding-top', '0');
    }

}

fixed();
$(window).scroll(function () {
    fixed();
});


/**
 * 视频曝光量对象(仅阅读数)
 * @type {{}}
 */

var exposure = {
    //懒加载id集合，实时清零
    ids: [],
    //当前页面id集合
    idCollections: [],
    //最大id数发送请求
    maxLength: 4,
    //页面类型
    type: 1,
    //特例id集合
    sids: [],
    //视频详情页id集合
    sidCollections: [],

    //初始化，3秒执行一次
    _init: function () {
        setInterval(this.verify, "3000");
    },

    //发送请求
    verify: function () {
        if (Param.openStatistics == '1') {
            if (exposure.ids.length >= exposure.maxLength) {
                duplicateRemoval(exposure.ids, exposure.idCollections);
                if (exposure.ids.length >= exposure.maxLength) {
                    videoExposureLogic(exposure.ids, exposure.type, 'display_times');
                    exposure.idCollections = $.unique($.merge(exposure.idCollections, exposure.ids));
                    exposure.ids = [];
                }
            }
        }
    },

    //特例：无法使用懒加载
    special: function () {
        $(window).scroll(function () {
            if (Param.openStatistics == '1') {
                if ($(window).scrollTop() >= 300 && exposure.sids.length > 0) {
                    videoExposureLogic(exposure.sids, exposure.type, 'display_times');
                    exposure.sids = [];
                }
            }
        });
    }
};

/**
 * 去除新增重复数据
 * @param $new
 * @param $total
 */
function duplicateRemoval(newlys, total) {
    if (total.length === 0) {
        return newlys;
    }
    $.each(newlys, function (k, v) {
        if ($.inArray(v, total) !== -1) {
            exposure.ids.splice(k);
        } else {
            exposure.idCollections.push(v);
        }
    });
}

/**
 * 视频曝光相关统计
 * @returns {boolean}
 */
function videoExposureLogic() {
    if (!arguments[0] || !arguments[1] || arguments[2] == '') {
        return false;
    }
    ids = arguments[0];
    type = arguments[1];
    field = arguments[2];

    //记录曝光量
    $.ajax({
        type: "post",
        url: Url.videoExposure,
        data: {
            type: type,
            video_id: ids,
            field: field,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        dataType: "json",
        xhrFields: {
            withCredentials: true
        },
        success: function (message) {
        }
    });
}

/**
 * 课程提醒 评论回复提醒 点击阅读后状态改变
 * @param type
 * @param _self
 * @returns {boolean}
 */
function changeStatusForLessonOrComment(type, _self) {
    var $sid = _self.attr('data-reply-id');

    // 如果已经没有红色状态标记 不做处理
    if (_self.parents('.list').find('i.dian').length <= 0) {
        return false;
    }

    if (type == 3) {        // 课程提醒
        ajaxChangeBegin(Url.lessonNoticeStatusChange);
    } else if (type == 2) { // 视频评论
        ajaxChangeBegin(Url.videoCommentStatusChange);
    }

    /**
     * 后端记录表 改变提醒信息真实状态
     * @param _url
     */
    function ajaxChangeBegin(_url) {
        $.ajax({
            url: _url,
            type: 'post',
            data: {
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content'),
                'id': $sid
            },
            dataType: 'json',
            success: function (message) {
                if (0 == message.isError) {
                    totalNumDesc();         // 总未读数减一
                    selfRemovePoint(_self); // 红点去除
                }
            },
            error: function (res) {
                return false;
            }
        })
    }
}

/**
 * 总未读提醒数量减一
 */
function totalNumDesc() {
    var total_num = parseInt($('.news-icon.hasRead').find('i').text());
    total_num -= 1;

    if (total_num > 0) {
        $('.news-icon.hasRead').find('i').text(total_num);
    } else {
        $('.news-icon.hasRead').find('i').remove();
    }
}

/**
 * 除去自身对应的红色状态点
 * @param _dom
 */
function selfRemovePoint(_dom) {
    _dom.parents('.list').find('i.dian').remove();
}

/**
 * 多处登录提醒
 */
$(function () {
    $(".login-tips").on("click", ".close,.btn", function () {
        $(".login-tips").addClass("hide");
        window.location.reload();
    });
});

/**
 * 赠送VIP关闭弹窗按钮
 */
$(".v1,.v2 .close").on('click', function () {
    $(this).closest('.vip-win').addClass('hide');
});

$(".v2 .close-r").on('click', function () {
    $('.v2').addClass('hide');
});

$('.welfare-win').on('click', '.close', function() {
    $('#loginModal').addClass('hide');

});
$('.welfare-win2').on('click', '.close', function() {
    $('.welfare-win2').addClass('hide');
});


//输入字符按钮变色
function pointer() {
    var curLength = $('.add-album .txt').val().length;
    if (curLength > 0) {
        $('.add-album .btn').addClass('pointer')
    } else {
        $('.add-album .btn').removeClass('pointer')
    }
}

/**
 * 导航 标签点击次数统计
 */
$('p.tags-list-click a').bind('click', function () {
    var $this = $(this);
    var $parent_tag_id = $this.parent('.tags-list-click').attr('data-parent-tag-id');
    var $parent_tag_name = $this.parent('.tags-list-click').attr('data-parent-tag-name');
    var $tag_id = $this.attr('data-tag-id');
    var $tag_name = $this.attr('data-tag-name');
    var $class_id = $this.parent('.tags-list-click').attr('data-class');

    $.ajax({
        url: Url.tagClickStatistics,
        dataType: 'Json',
        method: 'Post',
        data: {
            'parent_tag_id': $parent_tag_id,
            'tag_id': $tag_id,
            'parent_tag_name': $parent_tag_name,
            'tag_name': $tag_name,
            'class': $class_id
        },
        success: function ($res) {

        }
    });
});

/**
 * 首页点击统计
 * @param $position_id
 */
function pagePositionClick($position_id) {

    $.ajax({
        url: Url.pagePositionClick,
        dataType: 'Json',
        method: 'Post',
        data: {
            'position_id': $position_id
        },
        success: function ($res) {

        }
    });
}

/**
 * 广告统计
 */
function adClick(type, id) {
    $.ajax({
        url: Url.adClick,
        dataType: 'Json',
        method: 'Post',
        xhrFields: {
            withCredentials: true
        },
        data: {
            type: type,
            id: id,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function ($res) {

        }
    });
}

/**
 * 签到统计
 */
function signClickRecord(type) {
    $.ajax({
        url: Url.signClick,
        dataType: 'Json',
        method: 'Post',
        xhrFields: {
            withCredentials: true
        },
        data: {
            type: type,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function ($res) {

        }
    });
}

/**
 * 邀新活动点击统计
 */
function inviteClick(type) {
    $.ajax({
        url: Url.inviteClickUrl,
        dataType: 'Json',
        method: 'Post',
        xhrFields: {
            withCredentials: true
        },
        data: {
            "button_type": type,
            "client_type":0,
            "uid":Param.uid,
            "uv":Param.uv_id,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function () {

        }
    });
}

/**
 * 邀新活动访问统计
 */
function inviteView(type) {
    $.ajax({
        url: Url.inviteViewUrl,
        dataType: 'Json',
        method: 'Post',
        xhrFields: {
            withCredentials: true
        },
        data: {
            "view_type": type,
            "client_type":0,
            "uid":Param.uid,
            "uv":Param.uv_id,
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        success: function () {

        }
    });
}

/**
 *统计
 * @param url             url
 * @param data            object
 * @param withCredentials true|false
 */
function sendStatisticsCommonFunction(url, data, withCredentials) {
    $.ajax({
        url: url,
        dataType: 'json',
        method: 'Post',
        data: data,
        xhrFields: {
            withCredentials: withCredentials
        },
        success: function ($res) {
        }
    });
}

/**
 * 打开客服按钮
 */
function open_kefu(){
    window.open(Param.customer_service_url, '_blank');
}

/**
 * 底部友链左右滑动
 */
function friendSlide() {
    var cm = $('.friends-link .slide-m').width();
    sm = $('.friends-link .link-m').width();
    dm = sm - cm;
    if (sm > cm) {
        $('.friends-link .link-m').css({
            left: '0',
        });
        $('.link-t .next').show();
        $('.link-t').on('click', '.next', function () {
            $('.friends-link .link-m').css({
                left: -dm,
            });
            $(this).hide();
            $('.prev').show();
        });
        $('.link-t').on('click', '.prev', function () {
            $('.friends-link .link-m').css({
                left: '0'
            });
            $(this).hide();
            $('.next').show();
        });
    } else {
        $('.link-t .next').hide();
    }

}

friendSlide();
$(window).resize(function () {
    friendSlide();
    actualCombatWinTips();
});



//倒计时
if(Param.hasOwnProperty('needActivityOldUser') && Param.needActivityOldUser == '1'){
    var intDiff = parseInt(Param.ActivityOldUserexpire); //倒计时总秒数量

    function timer(intDiff) {
        window.setInterval(function () {
            var day = 00,
                hour = 00,
                minute = 00,
                second = 00; //时间默认值
            if (intDiff > 0) {
                day = Math.floor(intDiff / (60 * 60 * 24));
                hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            // $('#day_show').html(day);
            $('#hour_view,#hour_show').html('<s id="h"></s>' + hour);
            $('#min_view,#min_show').html('<s></s>' + minute);
            $('#sec_view,#sec_show').html('<s></s>' + second);
            intDiff--;
        }, 1000);
    }
    $(function () {
        timer(intDiff);
        $(".zhek-win .close-btn").on('click', function(){
            $(".zhek-win").addClass('hide');
            if(Param.isHome === '1'){
                $(".side-zhek").removeClass('hide');
            }
        });
        $(".sale-win .close-btn").on('click', function(){
            $(".sale-win").addClass('hide');
            if(Param.isHome === '1'){
                $(".side-sale").removeClass('hide');
            }
        });
    });
}



//2021双11刮奖
 if (Param.hasOwnProperty('activityOldUser20211101')) {
     var scratchTimer
     var scratchTime

     function scratch(){
         if (!$('.act-scratch').hasClass('hide')) {
             $('.act-scratch .a-small em').html('5s');
             scratchTime = 5;
             scratchTimer = setInterval(function () {
                 scratchTime-=1;
                 if (scratchTime < 1 || $('.act-scratch .scratch').attr('data-type')) {
                     scratchTime = 0;
                     clearInterval(scratchTimer);
                     if (!$('.act-scratch .scratch').attr('data-type')) {
                         layer.msg('系统已协助刮奖');
                     }
                     $('.act-scratch .scratch').click();
                 }
                 $('.act-scratch .a-small em').html(scratchTime+'s');
             },1000);
         }
     }
     scratch()
    $('.act-scratch .scratch').on('click',function () {
        $(this).attr('data-type',1);
        $.ajax({
            url: Param.activityOldUser20211101.activityLifeLongLottery,
            dataType: 'Json',
            method: 'post',
            data: {
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
            },
            success: function (res) {
                $('.act-scratch .bg-2 .coupon').find('em').html( res.data.discount );
                $('.act-scratch .bg-1').addClass('hide');
                $('.act-scratch .bg-2').removeClass('hide');
            }
        });
    });
    $('.show-act-scratch').click(function(){
        $(this).addClass('hide')
        $('.act-scratch').removeClass('hide')
        scratch()
    })
     $('.show-act-scratch-left').click(function(){
         $('.act-scratch').removeClass('hide')
         scratch()
     })

    var scratchStarttime = Param.activityOldUser20211101.expire * 1000;
    setInterval(function () {
        var nowtime = new Date();
        var time = scratchStarttime - nowtime;
        var day,hour,minute,seconds,millisecond;
        if (time > 0) {
            day = parseInt(time / 1000 / 60 / 60 / 24);
            hour = parseInt(time / 1000 / 60 / 60 % 24);
            minute = parseInt(time / 1000 / 60 % 60);
            seconds = parseInt(time / 1000 % 60);
            millisecond = parseInt(time % 1000);
        } else {
            hour=minute=seconds='00';
            millisecond='000';
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour,2);
        minute = PrefixInteger(minute,2);
        seconds = PrefixInteger(seconds,2);
        millisecond = PrefixInteger(millisecond, 3);
        $('.act-scratch .cd-time i,.act-scratch-small .cd-time i').html(hour+':'+minute+':'+seconds+':'+millisecond)
    }, 31);

    $('.act-scratch .act-close').on('click',function () {
        $('.act-scratch').addClass('hide');
        $('.act-scratch-small').removeClass('hide');
        clearInterval(scratchTimer);
    });
     $('.act-scratch .bg-2 .act-close').on('click',function () {
         window.location.reload()
     });

    $('.act-scratch-small .act-close').on('click',function () {
        $('.act-scratch-small').addClass('hide');
        $('.act-scratch-left').removeClass('hide');
        $.ajax({
            url: Param.activityOldUser20211101.leftCloseUrl,
            dataType: 'Json',
            method: 'post',
            data: {
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
            },
            success: function ($res) {
            }
        });
    });
}

//20211201终身500活动
if (Param.hasOwnProperty('activityOldUser20211201')) {
    var luckdrawTimer
    var luckdrawTime
    var luckdrawStarttime = Param.activityOldUser20211201.expire * 1000;


    function luckdraw(){
        if (!$('.act-luckdraw').hasClass('hide')) {
            $('.act-luckdraw .a-small').html('5s');
            luckdrawTime = 5;
            luckdrawTimer = setInterval(function () {
                luckdrawTime-=1;
                if (luckdrawTime < 1) {
                    luckdrawTime = 0;
                    clearInterval(luckdrawTimer);
                    if (!$('.act-luckdraw .luckdraw').attr('data-type')) {
                        $('.act-luckdraw .luckdraw').click();
                        layer.msg('已自动领取红包');
                    }
                }
                $('.act-luckdraw .a-small').html(luckdrawTime+'s');
            },1000);
        }
    }
    luckdraw()
   $('.act-luckdraw .luckdraw').on('click',function () {
       $(this).attr('data-type',1);
       $.ajax({
           url: Param.activityOldUser20211201.activityLifeLongLottery,
           dataType: 'Json',
           method: 'post',
           data: {
               '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
           },
           success: function (res) {
               $('.act-luckdraw .bg-2 .coupon').find('em').html( res.data.discount );
               $('.act-luckdraw .bg-1').addClass('hide');
               $('.act-luckdraw .bg-2').removeClass('hide');
               luckdrawStarttime = new Date().getTime() + 3600*3*1000;
           }
       });
   });
   $('.show-act-luckdraw').click(function(){
       $(this).addClass('hide')
       $('.act-luckdraw').removeClass('hide')
       luckdraw()
   })
    $('.show-act-luckdraw-left').click(function(){
        $('.act-luckdraw').removeClass('hide')
        luckdraw()
    })

    $('.act-luckdraw .bg-2 .txt span').hover(function () {
        $('.act-luckdraw .bg-2 .txt2').removeClass('hide');
    },function () {
        $('.act-luckdraw .bg-2 .txt2').addClass('hide');
    });

   setInterval(function () {
       var nowtime = new Date();
       var time = luckdrawStarttime - nowtime;
       var day,hour,minute,seconds,millisecond;
       if (time > 0) {
           day = parseInt(time / 1000 / 60 / 60 / 24);
           hour = parseInt(time / 1000 / 60 / 60 % 24);
           minute = parseInt(time / 1000 / 60 % 60);
           seconds = parseInt(time / 1000 % 60);
           millisecond = parseInt(time % 1000);
       } else {
           hour=minute=seconds='00';
           millisecond='000';
       }
       function PrefixInteger(num, length) {
           return (Array(length).join("0") + num).slice(-length);
       }
       hour = PrefixInteger(hour,2);
       minute = PrefixInteger(minute,2);
       seconds = PrefixInteger(seconds,2);
       millisecond = PrefixInteger(millisecond, 3);
       $('.act-luckdraw .cd-time i,.act-luckdraw-small .cd-time i').html(hour+':'+minute+':'+seconds+':'+millisecond)
   }, 31);

   $('.act-luckdraw .act-close').on('click',function () {
       $('.act-luckdraw').addClass('hide');
       $('.act-luckdraw-small').removeClass('hide');
       clearInterval(luckdrawTimer);
   });
    $('.act-luckdraw .bg-2 .act-close').on('click',function () {
        window.location.reload()
    });

   $('.act-luckdraw-small .act-close').on('click',function () {
       $('.act-luckdraw-small').addClass('hide');
       $('.act-luckdraw-left').removeClass('hide');
       $.ajax({
           url: Param.activityOldUser20211201.leftCloseUrl,
           dataType: 'Json',
           method: 'post',
           data: {
               '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
           },
           success: function ($res) {
           }
       });
   });
}

 //20220311终身500活动
 if (Param.hasOwnProperty('activityOldUser20220311')) {
     var luckdrawTimer
     var luckdrawTime
     var luckdrawStarttime = Param.activityOldUser20220311.expire * 1000;
     var luckdrawStarttime = Param.activityOldUser20220311.expire * 1000;

     $('.act-luckdraw .bg-2 .txt').hover(function () {
         $('.act-luckdraw .bg-2 .txt2').removeClass('hide');
     },function () {
         $('.act-luckdraw .bg-2 .txt2').addClass('hide');
     });

     setInterval(function () {
         var nowtime = new Date();
         var time = luckdrawStarttime - nowtime;
         var day,hour,minute,seconds,millisecond;
         if (time > 0) {
             day = parseInt(time / 1000 / 60 / 60 / 24);
             hour = parseInt(time / 1000 / 60 / 60 % 24);
             minute = parseInt(time / 1000 / 60 % 60);
             seconds = parseInt(time / 1000 % 60);
             millisecond = parseInt(time % 1000);
         } else {
             hour=minute=seconds='00';
             millisecond='000';
         }
         function PrefixInteger(num, length) {
             return (Array(length).join("0") + num).slice(-length);
         }
         hour = PrefixInteger(hour,2);
         minute = PrefixInteger(minute,2);
         seconds = PrefixInteger(seconds,2);
         millisecond = PrefixInteger(millisecond, 3);
         $('.act-luckdraw-small .cd-time i').html(hour+':'+minute+':'+seconds+':'+millisecond)
         $('.act-luckdraw .cd-time i').html(hour+':'+minute+':'+seconds+':'+millisecond)
     }, 31);

     $('.act-luckdraw .act-close').on('click',function () {
         $('.act-luckdraw').addClass('hide');
         $('.act-luckdraw-small').removeClass('hide');
         clearInterval(luckdrawTimer);
         window.location.reload();
     });

     $('.act-luckdraw-small .act-close').on('click',function () {
         $('.act-luckdraw-small').addClass('hide');
     });
 }

//0717活动
if(Param.hasOwnProperty('oldUser20200717')){
    var starttime = new Date(Param.oldUser20200717.expiredAt);
    setInterval(function () {
        var nowtime = new Date();
        var time = starttime - nowtime;
        if (time > 0) {
            var day = parseInt(time / 1000 / 60 / 60 / 24);
            var hour = parseInt(time / 1000 / 60 / 60 % 24);
            var minute = parseInt(time / 1000 / 60 % 60);
            var seconds = parseInt(time / 1000 % 60);
            var millisecond = parseInt(time % 1000);
        } else{
            hour=minute=seconds="00"
            millisecond="000"
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour,2);
        minute = PrefixInteger(minute,2);
        seconds = PrefixInteger(seconds,2);
        $('.ActivityNewUser300 .activity-countDown').html("<i>" + hour + "</i>:<i>" + minute + "</i>:<i>" + seconds + "</i>");
        $('.smallActivityNewUser300 .activity-countDown').html("<i>" + hour + "</i>:<i>" + minute + "</i>:<i>" + seconds + "</i>");
    }, 31);

    $(".ActivityNewUser300 .activity-close").click(function () {
        $(".ActivityNewUser300").addClass("hide")
        $(".smallActivityNewUser300").removeClass("hide")
    })
    $(".smallActivityNewUser300 .smallActClose").click(function () {
        $(".smallActivityNewUser300").addClass("hide")
    })
    $(".ActivityNewUser300 .dont-tips").click(function () {
        $('.ActivityNewUser300').addClass('hide');
        $('.smallActivityNewUser300').addClass('hide');
        $.post(Param.oldUser20200717.activityOldUserLifelongNotRemindUrl, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
    })
}


if(Param.hasOwnProperty('oldUser20201111')){
    var luckTime;
    var starttime = Param.oldUser20201111.expiredAt + '000';
    setInterval(function () {
        var nowtime = luckTime ? luckTime :(new Date()).valueOf();
        var time = starttime - nowtime;
        if (time > 0) {
            var hour = parseInt(time / 1000 / 60 / 60 % 24);
            var minute = parseInt(time / 1000 / 60 % 60);
            var seconds = parseInt(time / 1000 % 60);
        } else {
            hour = minute = seconds = "00"
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour, 2);
        minute = PrefixInteger(minute, 2);
        seconds = PrefixInteger(seconds, 2);
        $('.Activity500 .activity-countDown,.smallActivity500 .activity-countDown').html('<i>' +  hour + "</i><em>:</em><i>" + minute + "</i><em>:</em><i>" + seconds + '</i>');
    }, 300);

    $(".Activity500 .activity-close").click(function () {
        $(".Activity500").addClass("hide");
        $(".smallActivity500").removeClass("hide");
    });
    $(".smallActivity500 .smallActClose").click(function () {
        $(".smallActivity500").addClass("hide");
    });
    $(".Activity500 .dont-tips").click(function () {
        $('.Activity500').addClass('hide');
        $('.smallActivity500').addClass('hide');
        $.post(Param.oldUser20201111.activityOldUserLifelongNotRemindUrl, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
    });
};



if(Param.hasOwnProperty('oldUser')){
    var luckTime;
    var starttime = Param.oldUser.expiredAt + '000';
    setInterval(function () {
        var nowtime = luckTime ? luckTime :(new Date()).valueOf();
        var time = starttime - nowtime;
        if (time > 0) {
            var hour = parseInt(time / 1000 / 60 / 60 % 24);
            var minute = parseInt(time / 1000 / 60 % 60);
            var seconds = parseInt(time / 1000 % 60);
        } else {
            hour = minute = seconds = "00"
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour, 2);
        minute = PrefixInteger(minute, 2);
        seconds = PrefixInteger(seconds, 2);
        $('.luck-drawed-win .countdown,.luck-drawed-win-small .countdown').html('<i>' +  hour + "</i><em>:</em><i>" + minute + "</i><em>:</em><i>" + seconds + '</i>');
    }, 300);

    $('.luck-drawed-win').on('click','.close',function(){
        $('.luck-drawed-win').addClass('hide');
        $('.luck-drawed-win-small').removeClass('hide');

    })
    $('.luck-drawed-win-small').on('click','.close',function(){
        $('.luck-drawed-win-small').addClass('hide')
    })
    $(".luck-drawed-win .dont-show").click(function () {
        $('.luck-drawed-win').addClass('hide');
        $('.luck-drawed-win-small').addClass('hide');
        $.post(Param.oldUser.activityOldUserLifelongNotRemindUrl, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
    })
};

if(Param.hasOwnProperty('activityOldUser20201212')){
    var started;
    var luckTime;//返回的抽奖事件
    var luckDraw = {
        init:function(){
            if(!$('div#activityOldUserLifelong20201212').hasClass('hide')){
                this.luckDown();
            }
            if(!$('div#activityOldUserLifelongSmall20201212').hasClass('hide')){
                this.countDown('div#activityOldUserLifelongSmall20201212 .countdown', Param.activityOldUser20201212.expire)
            }
            this.event();
        },
        // 抽奖倒计时
        luckDown:function(){
            var that = this;
            that.n = 5;
            $('.raffle-win .draw-btn i').text('5')
            d = setInterval(function () {
                if (that.n > 0) {
                    that.n--;
                    $('.raffle-win .draw-btn i').text(that.n)
                }else{
                    that.draw()
                    clearInterval(d)
                }
            }, 1000);
        },
        // 领奖倒计时
        countDown: function (dom,t) {
            var starttime = t;
            setInterval(function () {
                var nowtime = luckTime ? luckTime :(new Date()).valueOf();
                var time = starttime - nowtime;
                if (time > 0) {
                    var hour = parseInt(time / 1000 / 60 / 60 % 24);
                    var minute = parseInt(time / 1000 / 60 % 60);
                    var seconds = parseInt(time / 1000 % 60);
                } else {
                    hour = minute = seconds = "00"
                }
                function PrefixInteger(num, length) {
                    return (Array(length).join("0") + num).slice(-length);
                }
                hour = PrefixInteger(hour, 2);
                minute = PrefixInteger(minute, 2);
                seconds = PrefixInteger(seconds, 2);
                $(dom).html( hour + ": " + minute + ": " + seconds);
            }, 300);
        },
        // 抽奖
        draw:function(){
            var that = this;
            if (!started) {

                var m = 5-that.n;
                that.p = (6 + m) * 1000;
                started = 1;
                $('.raffle-win .draw-btn span').html('(抽奖中...)');
                $.post(Param.activityOldUser20201212.url, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
                clearInterval(d);
                $('.luck-list').css('animation','scl 6s ease-out forwards');
                if (!that.s) {
                    $('.luck-list').bind('animationend',function(){
                        $('.raffle-win').addClass('active')
                        setTimeout(function () {
                            var t = Date.parse(new Date()) + 108e5;//抽奖事件+3小时
                            that.countDown('.raffled-win .countdown span,.raffled-win-small .countdown', t)
                            $('.raffle-win').addClass('hide');
                            $('.raffle-win').removeClass('active')
                            $('.raffled-win').removeClass('hide')
                        }, 3000)
                    })
                }
            }
        },
        // 弹出中奖弹窗
        luckwin:function(p){
            var that = this;
            h = setTimeout(function () {
                var t = Date.parse(new Date()) + 108e5;//抽奖事件+3小时
                that.countDown('.raffled-win .countdown span,.raffled-win-small .countdown', t)
                $('.raffle-win').addClass('hide');
                $('.raffled-win').removeClass('hide')
            }, p)
        },
        // 事件
        event:function(){
            var that = this;
            // 点击抽奖
            $('.raffle-win .draw-btn').click(function(){
                that.draw();
            });
            // 关闭抽奖弹窗
            $('.raffle-win .close').click(function(){
                $('.raffle-win').addClass('hide');
                if (started) {
                    $('.raffled-win-small').removeClass('hide');
                    that.luckwin(1000);
                    that.s = 1;

                }else{
                    $('.raffle-win-small').removeClass('hide');

                    clearInterval(d);
                }
            })
            // 关闭中奖弹窗
            $('.raffled-win .close').click(function () {
                $('.raffled-win').addClass('hide');
                $('.raffled-win-small').removeClass('hide');
            })
            // 点击左下角抽奖弹窗
            $('.raffle-win-small .btn').click(function () {
                $('.raffle-win-small').addClass('hide');
                $('.raffle-win').removeClass('hide');
                that.luckDown()
            })
            // 关闭左下角领奖弹窗
            $('.raffled-win-small .close').click(function () {
                $('.raffled-win-small').addClass('hide')
            })
            $('.raffle-win-small .close').click(function () {
                $('.raffle-win-small').addClass('hide')
            })
            // 不再提示
            $(".raffle-win .not-show,.raffled-win .not-show").click(function () {
                $('.raffle-win,.raffled-win').addClass('hide');
                $.post(Param.oldUser.activityOldUserLifelongNotRemindUrl, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
            })
        }
    }
    luckDraw.init()
}

if(Param.hasOwnProperty('activityOldUser20201221')){
    var luckTime;
    var starttime = Param.activityOldUser20201221.expire + '000';
    var downTime = function(){
        var nowtime = luckTime ? luckTime :(new Date()).valueOf();
        var time = starttime - nowtime;
        var hour,minute,seconds,millisecond;
        if (time > 0) {
            hour = parseInt(time / 1000 / 60 / 60 % 24);
            minute = parseInt(time / 1000 / 60 % 60);
            seconds = parseInt(time / 1000 % 60);
            millisecond = parseInt(time % 1000)
        } else {
            hour = minute = seconds = "00"
            millisecond = '000'
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour, 2);
        minute = PrefixInteger(minute, 2);
        seconds = PrefixInteger(seconds, 2);
        millisecond = PrefixInteger(millisecond, 3);
        if(Param.activityOldUser20201221.hasOwnProperty('version') && Param.activityOldUser20201221.version == '20210201'){
            $('.year-end-win .win2 .time i,.year-end-win-small .p1 i').html(hour + '<em>:</em>' + minute + '<em>:</em>' + seconds + '<em>:</em>' + millisecond)
        }
        $('.year-end-win-small .countdown i').html(hour + '<em>:</em>' + minute + '<em>:</em>' + seconds);
    }
    downTime()
    setInterval(function () {
        downTime()
    }, 44);



    // 关闭中奖弹窗
    $('.year-end-win .close').click(function () {
        $('.year-end-win').addClass('hide');
        $('.year-end-win-small').removeClass('hide');
    })
    // 关闭左下角领奖弹窗
    $('.year-end-win-small .close').click(function () {
        $('.year-end-win-small').addClass('hide')
    })
    // 不再提示
    $(".year-end-win .not-show").click(function () {
        $('.year-end-win').addClass('hide');
        $.post(Param.activityOldUser20201221.activityOldUserLifelongNotRemindUrl, {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
    })
};
if(Param.hasOwnProperty('activityOldUser20211015')){
    var luckTime;
    var starttime = Param.activityOldUser20211015.expire + '000';
    var downTime = function(){
        var nowtime = luckTime ? luckTime :(new Date()).valueOf();
        var time = starttime - nowtime;
        var hour,minute,seconds,millisecond;
        if (time > 0) {
            hour = parseInt(time / 1000 / 60 / 60 % 24);
            minute = parseInt(time / 1000 / 60 % 60);
            seconds = parseInt(time / 1000 % 60);
            millisecond = parseInt(time % 1000)
        } else {
            hour = minute = seconds = "00"
            millisecond = '000'
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        hour = PrefixInteger(hour, 2);
        minute = PrefixInteger(minute, 2);
        seconds = PrefixInteger(seconds, 2);
        millisecond = PrefixInteger(millisecond, 3);
        if(Param.activityOldUser20211015.hasOwnProperty('version') && Param.activityOldUser20211015.version == '20211015'){
            $('.lifelong-vip-win .time i,.lifelong-vip-win-small .p1 i').html(hour + '<em>:</em>' + minute + '<em>:</em>' + seconds + '<em>:</em>' + millisecond)
        }
    }
    downTime()
    setInterval(function () {
        downTime()
    }, 44);
    // 关闭中奖弹窗
    $('.lifelong-vip-win .close').click(function () {
        $('.lifelong-vip-win').addClass('hide');
        $('.lifelong-vip-win-small').removeClass('hide');
    })
    // 关闭左下角领奖弹窗
    $('.lifelong-vip-win-small .close').click(function () {
        $('.lifelong-vip-win-small').addClass('hide')
        $('.lifelong-vip-win-pos').removeClass('hide')
    })
    $(".lifelong-vip-win-small .close").on('click',function () {
        $.ajax({
            url: Param.activityOldUser20211015.leftCloseUrl,
            dataType: 'Json',
            method: 'post',
            data: {
                '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
            },
            success: function ($res) {

            }
        });
    });
};
// 新用户充值活动
if($('.new-user-win').length){
    setInterval(function () {
        var nowtime = new Date();
        var starttime = Param.user_created_at * 1000 + 43200000
        var time = starttime - nowtime;
        var day, hour, minute, seconds, millisecond;
        if (time > 0) {
            hour = parseInt(time / 1000 / 60 / 60 % 24);
            minute = parseInt(time / 1000 / 60 % 60);
            seconds = parseInt(time / 1000 % 60);
            millisecond = parseInt(time % 1000);
        } else {
            hour = minute = seconds = '00'
            millisecond = '000'
        }

        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }

        hour = PrefixInteger(hour, 2);
        minute = PrefixInteger(minute, 2);
        seconds = PrefixInteger(seconds, 2);
        millisecond = PrefixInteger(millisecond, 3);

        $('.new-user-win span,.new-user-win-s span').html(hour + ':' + minute + ':' + seconds + ':' + millisecond);
    }, 31);
    $('.new-user-win .close').click(function(){
        $('.new-user-win').addClass('hide')
        $('.new-user-win-s').removeClass('hide')
    })

    $('.new-user-win-s .close').click(function(){
        $('.new-user-win-s').addClass('hide')
    })
    $('.new-user-win .btn').click(function(){
        $('.new-user-win').addClass('scale')
        setTimeout(function(){
            $('.new-user-win').addClass('hide').removeClass('scale')
        },1500)
        $('.new-user-win-s').removeClass('hide')
    })
}

/**
 * 倒计时
 * @param timeContainer 时间容器
 * @param intSeconds    初始化秒数
 */
function countDownTimer(timeContainer, intSeconds) {
    window.setInterval(function () {
        var day = 00,
            hour = 00,
            minute = 00,
            second = 00; //时间默认值
        if (intSeconds > 0) {
            day = Math.floor(intSeconds / (60 * 60 * 24));
            hour = Math.floor(intSeconds / (60 * 60)) - (day * 24);
            minute = Math.floor(intSeconds / 60) - (day * 24 * 60) - (hour * 60);
            second = Math.floor(intSeconds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
        }
        if (minute <= 9) minute = '0' + minute;
        if (second <= 9) second = '0' + second;
        timeContainer.find('.day').html(day);
        timeContainer.find('.hour').html('<s id="h"></s>' + hour);
        timeContainer.find('.minute').html('<s></s>' + minute);
        timeContainer.find('.second').html('<s></s>' + second);
        intSeconds--;
    }, 1000);
}

function Huke_Post(url, params, callback){
    if( typeof params == 'object' && typeof params['_csrf-frontend']=='undefined' ){
        params['_csrf-frontend'] = $('meta[name="csrf-token"]').attr('content');
    }
    $.post(url , params, function (s) {
        if( typeof callback=='function' ){
            callback(s);
        }
    }, 'json');
}

function Huke_Ajax(url, params, callback, method, dataType){
    if( typeof params == 'object' && params['_csrf-frontend']==void 0 ){
        params['_csrf-frontend'] = $('meta[name="csrf-token"]').attr('content');
    }
    if( method==void 0 ){
        method = 'POST';
    }
    if( dataType==void 0 ){
        dataType = 'JSON';
    }
    $.ajax({
        url: url,
        method: method,
        dataType: dataType,
        data: params,
        xhrFields: {
            withCredentials: true
        },
        success: function (s) {
            if( typeof callback=='function' ){
                callback(s);
            }
        },
    });
}

function statistics_play(){
    Huke_Ajax(Url.StatisticsPlayUrl,{'video_id':Param.video_id, 'source':Param.from, 'uv_id': Param.uv_id},function(){});
}

// ab测试登陆注册
function statistics_play_ab_test_siginin() {
    Huke_Ajax(Url.StatisticsPlaySigninAbTestUrl,{'uv_id': Param.uv_id},function(){});
}

function viewImgWin(img) {
    $('body').append('<div class="big-imgwin"><div class="big-imgwin-mask"></div><div class="big-imgwin-box"><a onclick="return false;" href="javascript:;" class="close"></a><img src="'+ img +'" alt=""></div></div>');
    $('.big-imgwin').on('click', '.close', function() {
        $('.big-imgwin').remove()
    });
}

// ctrl+d 收藏弹窗
$('.mark-btn').on('click', '.show-btn', function() {
    $('.bookmark-win').addClass('show');
});
$('.mark-btn').click(function(e) {
    e.stopPropagation();
});
$('.bookmark-win').on('click', '.btn span', function() {
    $('.bookmark-win').removeClass('show')
});
$(document).click(function() {
    $('.bookmark-win').removeClass('show')
});

//控制注册勾选协议
$('#loginModal-t2').on('click', '.agree-deal label', function () {
    $(this).parent().siblings('.check-tips').show();
    $(this).find('.checkput').prop('checked', true);
    var hidd = $(this).parent().siblings('.check-tips');
    setTimeout(function(){hidd.hide()}, 2000);
});
//导航直播关闭按钮
$(".nav-list .live-tip .close").click(function(){
    $(".nav-list .live-tip").hide();
});

$(".live-tip").mouseover(function(e){
    $(this).parent().removeClass("nav-live-header");
    e.stopPropagation();
}).mouseout(function(e){
    $(this).parent().addClass("nav-live-header");
    e.stopPropagation();
});

//软件入门月卡特权即将过期提示
$('.vip-head-tips').on('click', '.close', function() {
    $('.vip-head-tips').addClass('hide');
    $.ajax({
        type: "post",
        url: '//huke88.com/site/close-monthly-card',
        data: {
            '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
        },
        dataType: "json",
        success: function (message) {}
    });
});

if(Param.hasOwnProperty('userTierTopTime') || Param.hasOwnProperty('userTierButtomTime')){

    if(Param.hasOwnProperty('userTierTopTime')){
        var starttime =  new Date(Param.userTierTopTime);
    }else if(Param.hasOwnProperty('userTierButtomTime')){
        var starttime =  new Date(Param.userTierButtomTime);
    }
    setInterval(function () {
        var nowtime = new Date();
        var time = starttime - nowtime;
        if($(".d-time").length < 0){
            return false;
        }

        if (time > 0) {
            var day = parseInt(time / 1000 / 60 / 60 / 24);
            var hour = parseInt(time / 1000 / 60 / 60 % 24);
            var minute = parseInt(time / 1000 / 60 % 60);
            var seconds = parseInt(time / 1000 % 60);
            var millisecond = parseInt(time % 1000);
        } else{
            hour=minute=seconds="00";
            millisecond = '000';
        }
        function PrefixInteger(num, length) {
            return (Array(length).join("0") + num).slice(-length);
        }
        day = PrefixInteger(day,2);
        hour = PrefixInteger(hour,2);
        minute = PrefixInteger(minute,2);
        seconds = PrefixInteger(seconds,2);
        millisecond = PrefixInteger(millisecond,3);
        $('.d-time').html("<i>" + hour + "</i><em>: </em><i>" + minute + "</i><em>: </em><i>" + seconds + "</i><em>: </em><i class='millisecondLabel'>" + millisecond + "</i>");
    }, 31);
    $(".userTierTopHead .topHeadCen .close").click(function () {
        $.post('/activity/user-tier-cookie', {type: 1,'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
        $('.userTierTopHead').slideUp();
    });
    $('.hand-cont-new .rightClose').on('click', function () {
        $.post('/activity/user-tier-cookie', {type: 2,'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
        $('.new-act-big').stop().animate({
            left: "-100%"
        }, 600, function () {
            $('.new-act-small').stop().animate({
                left: '0'
            }, 300).show();
        });
    });

    $('.new-act-small .hand-once-box .close').on('click', function () {
        $('.new-act-small .hand-once-box').hide()
    })
}
// 头部实战营入口提示
var actualCombatWinTips = function(){
    if ($('#new-header .szy').length > 0) {
        var l = $('#new-header .szy').offset().left;
        $('.actual-combat-win-tips').css('left', l)
    }
}
actualCombatWinTips()
$('.actual-combat-win-tips').show()
$('.actual-combat-win-tips').on('click', '.close', function() {
    $('.actual-combat-win-tips').hide()
});

/************ start bottom banner *************/
// 默認關閉之後全站隐藏
if ( typeof($.cookie('bottom_expire')) != 'undefined' ) {
    $(".guide-bottom").addClass("hide");
}

$(".guide-bottom .close").click(function(){
    var nowdate= Date.parse(new Date()); //获取当前时间
    var enddate= new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 //获取24点时间
    var date = new Date();
    date. setTime (date.getTime()+ (enddate-nowdate));
    $.cookie('bottom_expire', enddate-nowdate, { expires: date });
    $(".guide-bottom").addClass("hide");
});
/************ stop bottom banner *************/

function addVideoPlaySigninAbTest() {
    Huke_Ajax(Url.addVideoSigninRecordSessionUrl,{},function(){});
}

//新手任务右下角浮动窗提示关闭
$(".bar-list.tiro .r-tips small").click(function(){
    $(".bar-list.tiro .r-tips").addClass("hide");
    var data = {
        'uid': Param.uid,
        'uv': Param.uv_id,
        'type':$(this).attr('type'),
        '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
    };
    $.post(Url.novicePopupRecord, data, function (res) {
    });
});

$('#right-bar .appadd .pos .close em').click(function () {
    $('#right-bar .appadd').removeClass('isShow');
    $('#right-bar .appaddwm').removeClass('hide');
    rightCodeResize();
    var t = setInterval(function () {
        $('#right-bar .appaddwm').addClass('hide');
        clearInterval(t);
    },500);
});;

//设置cookie
// function homeQRCode(){
//     if($.cookie('homeQRCode')){
//         $('#right-bar .appadd').removeClass('isShow');
//     }else{
//         $.cookie('homeQRCode',1);
//         $('#right-bar .appadd').addClass('isShow');
//     }
// }
// homeQRCode();

function rightCodeResize(){
    var windowHeight = $(window).height();
    if (windowHeight<800) {
        if ($('#right-bar .appaddw .appadd').hasClass('isShow')){
            $('#right-bar .appadd .pos').css({"top":"-193px"});
        } else {
            $('#right-bar .appadd .pos').css({"top":"-178px"});
        }
    } else {
        $('#right-bar .appadd .pos').css({"top":"0"});
    }
}
rightCodeResize();
$(window).resize(function () {
    rightCodeResize();
});

function resizeRightTips() {
    var h = $(window).height();
    if (h<800) {
        $("#right-bar .tips-classify-r").css({"margin-top":"-68px"});
    } else {
        $("#right-bar .tips-classify-r").css({"margin-top":"-88px"});
    }
}
resizeRightTips();
$(window).resize(function () {
    resizeRightTips();
});


var enterpriseWxSidebar = {
    init: function () {
        if($('#right-bar .welfare').length > 0){
            this.bind();
            this.showAuto();
        }
    },
    bind:function(){
        var $this = this;
        var bindTimeIdentify = false;
        $('#right-bar .welfare').on('click',function () {
            $('.welfare-popup').removeClass('hide');

            if(!bindTimeIdentify){
                $this.cdTimeFn();
                bindTimeIdentify = true;
            }
            $('#right-bar .welfare .receive-welfare em').addClass('hide');
        });
        $('#right-bar .welfare').hover(function () {},function () {
            $('#right-bar .welfare .left-tips').removeClass('active');
        });
        $('.welfare-popup .close').on('click',function () {
            $('.welfare-popup').addClass('hide');
        });
        $('.welfare-popup .close-tips').on('click',function () {
            $.ajax({
                type: "post",
                url: Url.enterpriseWxClose,
                data: {'_csrf-frontend': $('meta[name="csrf-token"]').attr('content'),},
                dataType: "json",
                success: function (response) {
                    if(response.status == 200){
                        $('.welfare-popup').addClass('hide');
                        $('#right-bar .welfare').addClass('hide');
                        return false;
                    }else{
                        hayer.msg(response.msg);
                    }
                }
            });
        });
    },
    showAuto: function(){
        var showAutoCookieName = 'ENTERPRISE_SHOW_AUTO_NUM';
        var val = $.cookie(showAutoCookieName);
        if(val == undefined){
            val = 0;
        }
        val = parseInt(val);
        if(val <= 2){
            if(val == 2){
                $('#right-bar .welfare .left-tips').addClass('active');
                $('#right-bar .welfare .receive-welfare em').removeClass('hide');
            }
            $.cookie(showAutoCookieName, val+1, {expires: Tools.zeroPoint(), path: '/'});
        }
    },

    cdTimeFn:function () {
        var endTime = Number((new Date()).valueOf()) + 1000 * 3600;

        setInterval(function () {
            var nowTime = (new Date()).valueOf();
            var time = endTime-nowTime;
            var hour,minute,seconds;
            if (time > 0) {
                hour = parseInt(time / 1000 / 60 / 60 % 24);
                minute = parseInt(time / 1000 / 60 % 60);
                seconds = parseInt(time / 1000 % 60);
            } else {
                endTime = endTime + 1000 * 3600;
            }
            function PrefixInteger(num, length) {
                return (Array(length).join("0") + num).slice(-length);
            }
            hour = PrefixInteger(hour, 2);
            minute = PrefixInteger(minute, 2);
            seconds = PrefixInteger(seconds, 2);
            $('.welfare-popup .time-tips em').html(minute+'分'+seconds+'秒');
        }, 31);
    },
};
enterpriseWxSidebar.init();

// 支付页用户协议弹窗
$('.service-agreement-win').on('click','.close,.agree-btn span',function(){
    $('.service-agreement-win').hide()
})
$('.service-agreement-box').on('click','span',function(){
    if($(this).attr('data-type') == 2){
        $(".service-agreement-win .vip-monthly-win-m").show();
        $(".service-agreement-win .vip-base-win-m").hide();
    }else{
        $(".service-agreement-win .vip-monthly-win-m").hide();
        $(".service-agreement-win .vip-base-win-m").show();
    }
    $('.service-agreement-win').show()
})


// 判断是否是今天 昨天
function isTime(time) {
    var myDate = new Date();
    //获取当前年
    var year=myDate.getFullYear();
    //获取当前月
    var month=myDate.getMonth()+1;
    //获取当前日
    var day=myDate.getDate();
    var date = new Date(year+'/'+month+'/'+day).getTime() - new Date(time).getTime();
    if(date <= 0){
        return 1;
    }else if(date < 86400000){
        return 2;
    }else{
        return 3;
    }
}

$(".tips-cashback .close").on('click', function () {
    $.post('/activity/close-cashback-book', {type: 1,'_csrf-frontend': $('meta[name="csrf-token"]').attr('content')}, function () {});
    $(".tips-cashback").remove();
});

/* 头部登录按钮下拉触发登录 */
$('#new-header .login .header-login-hover-btn').click(function () {
    toLogin('header-login-hover-btn');
    var method = $(this).data('method');
    method && $('.lrframe-box-v1 .tab-main .first .' + method + '-login-btn').click();
});
/* 底部固定栏触发登录 */
$('.guide-bottom .r-login .guide-bottom-identify').click(function () {
    var identify = $(this).attr('data-identify');
    toLogin(identify);
    var method = $(this).data('method');
    method && $('.lrframe-box-v1 .tab-main .first .' + method + '-login-btn').click();
});

// 右侧bar 新人福利hover隐藏
var discountShow = localStorage.getItem("discount-show");
if(!discountShow){
    $('#right-bar .dis-tips').show();
}
$('#right-bar .discount-bar').hover(function(){
    localStorage.setItem("discount-show",0);
},function(){
    $('#right-bar .dis-tips').hide();
})

// 右侧bar 领取训练营
$('.get-free-course-win').on('click','.list',function(){
    $(this).addClass('active').siblings().removeClass('active')
    $('.get-free-course-win .get-course-btn span').addClass('active')
})

// 右侧bar 点击领取训练营
$('.get-course-btn').on('click','span',function(){
    var l = $('.get-free-course-win .list').hasClass('active');
    if(l >= 1){
        var training_id = $('.get-free-course-win .active input[name=id]').val();
        $.ajax({
            url: Url.benefitsreceiveTrainingUrl,
            data: {
                "_csrf-frontend": $('meta[name="csrf-token"]').attr("content"),
                "training_id" : training_id,
            },
            method: 'post',
            dataType: "json",
            success: function (res) {
                if (res.status == 200) {
                    var con = $('.get-free-course-win .list.active').html();
                    var codeImg = $('.get-free-course-win .active input[name=teacher_qrcode]').val();
                    $('.get-free-course-win').hide()
                    $('.open-course-win').show();
                    $('.open-course-win .list').html(con)
                    $('.open-course-win .code-img').attr('src',codeImg);
                    $('.get-training').text('已领取').removeClass('get-training').addClass('trained clicked')
                } else {
                    hayer.msg(res.msg);
                }
            }
        });
    }else{
        hayer.msg('请选择一个训练营')
    }
})
//领取训练营后直接弹出二维码弹窗
$('.discount-bar').on('click','.trained',function () {
    $('.open-course-win').show()
    $('.open-course-win .lazy').lazyload()
})
$('.get-free-course-win .close').click(function(){
    $('.get-free-course-win').hide()
})
$('.open-course-win .close').click(function(){
    $('.open-course-win').hide()
})
// 右侧bar 领取读书vip
$('#right-bar').on('click','.discount-bar .get-book',function(){
    $(this).addClass('clicked').text('已领取')
    $.ajax({
        type: 'POST',
        url: Url.weChatbenefitsQrCode,
        dataType: 'json',
        data: {
            'uv': Param.uv,
            "_csrf-frontend": $('meta[name="csrf-token"]').attr("content")
        },
        xhrFields: {
            withCredentials: true
        },
        success: function (res) {
            hayer.confirm('<p class="fz16 c333 mt24">扫码关注服务号 激活VIP特权</p><img src='+res.url+' alt="" class="code-img mt20"><p class="fz14 c999 mt15">打开微信“扫一扫”功能</p><p class="fz14 c999 mt12">关注虎课服务号</p>',
                {
                    btn: [],//按钮
                    btnColor: [] //按钮颜色 1白色 2黄色 3橙色 0不显示
                }, function () {
                    return false;
                }
            );
        }
    });
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

 // 获取训练营
 $('.discount-list').on('click','.get-training',function(){
     $('.get-free-course-win').show()
     $('.get-free-course-win .lazy').lazyload()
 })

createQrCodeCourse($('#right-bar .app-client .img'), '&ct=2');

function createQrCodeCourse(ele, text) {
    ele.QRCodeLogo({
        render: "canvas", //设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好
        text: Param.appQRCodePrefix + Param.appQRCodeParam + text, //扫描二维码后显示的内容,可以直接填一个网址，扫描二维码后自动跳向该链接
        width: "150", //二维码的宽度
        height: "150", //二维码的高度
        background: "#fff", //二维码的后景色
        foreground: "#000", //二维码的前景色
        src: Param.QRcodeLogo //二维码中间的图片
    });
}

 $(".act-prompt-1226-s .close").on('click',function () {
     $.ajax({
         url: Param.cashBackCloseLeftUrl,
         dataType: 'Json',
         method: 'post',
         data: {
             'activity_type' : Param.activity_type,
             '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
         },
         success: function ($res) {

         }
     });
 });

 $(".act-prompt-0109-s .close").on('click',function () {
     $.ajax({
         url: Param.cashBackCloseLeftUrl,
         dataType: 'Json',
         method: 'post',
         data: {
             'activity_type' : Param.activity_type,
             '_csrf-frontend': $('meta[name="csrf-token"]').attr('content')
         },
         success: function ($res) {

         }
     });
 });

 $('#navNewPublicLogo').click(function () {
     pagePositionClick(1022);
 })

 $('#new-header .tips-receive .a-btn').click(function () {
     $('#new-header .tips-receive').remove();
 })

 function uploadLimitHandle(res) {
     if(res.status === 501){
         bindPhoneWin();
         return false;
     }

     return true;
 }

 //设置cookie
 function setCookie(name, value, cookieTime) {
     var cookieTime = cookieTime || 365 * 60 * 60 * 24 * 1000;
     var exp = new Date();
     exp.setTime(exp.getTime() + cookieTime);
     document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
 }

 //获取cookie
 function getCookie(name) {
     var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
     if (arr = document.cookie.match(reg)){
         return unescape(arr[2]);
     } else {
         return 0;
     }
 }

 function addBackPhoneNumberTipsFn() {
     if (Param.uid != '0' && !getCookie('comAddBackPhoneNumTips'+Param.uid)) {
         var tipsEle = '<div id="com-add-back-phone-number">\n' +
             '    <div class="span">为提升您的体验以及提高学习效率，虎课可能会通过<br>用户手机号添加微信，如无此需求请在添加时予以拒绝</div>\n' +
             '    <a href="javascript:;" class="a-know">我已知晓</a>\n' +
             '</div>';

         $('body').append(tipsEle);

         $('#com-add-back-phone-number').animate({
             bottom: '15px',
         },500);

         function fadeOutFn() {
             $('#com-add-back-phone-number').animate({
                 bottom: '-999px',
             },500,function () {
                 $('#com-add-back-phone-number').remove();
             });
             clearInterval(tipsTimer);
             setCookie('comAddBackPhoneNumTips'+Param.uid, 1, 365 * 24 * 60 * 60 * 1000);
         }

         var tipsTimer = setInterval(function () {
             fadeOutFn();
         },5e3);

         $('#com-add-back-phone-number .a-know').on('click',function () {
             fadeOutFn();
         });
     }
 }


// 弹窗显示监听
function clickWinStatistics(){
    var watchDom = $('*[data-popup-id]')
    var config = { attributes: true, childList: true,subtree :true };
    var domArr = []
    // 当观察到变动时执行的回调函数
    var callback = function(mutationsList, observer) {
        for (var i = 0; i < mutationsList.length; i++) {
            var dom = mutationsList[i].target
            var display = dom.currentStyle ? dom.currentStyle['display'] : getComputedStyle(dom, null)['display']
            var attr = dom.dataset
            // 弹窗关闭后 从临时数组中删除
            // console.log(display);
            if(domArr.indexOf(attr) !== -1 && display === 'none'){
                console.log('clear',dom,display,attr,domArr);
                domArr.splice(domArr.indexOf(attr),1)
            }

            if(display !== 'none' && domArr.indexOf(attr) === -1 && dom.hasAttribute('data-popup-id')){
                console.log(dom,display,attr,domArr);
                watchPopupShow(dom.getAttribute('data-popup-id'),dom.getAttribute('data-popup-extend') || '')
                console.log('popupId:'+dom.getAttribute('data-popup-id'),'extendVal:'+ dom.getAttribute('data-popup-extend') || '');
                domArr.push(attr)
            }
        }

    };
    // 创建一个观察器实例并传入回调函数
    var observer = new MutationObserver(callback);
    var observerClick = new MutationObserver(callback);

    // 初始化监听
    if(watchDom.length){
        for (let i = 0; i < watchDom.length; i++) {
            const dom = watchDom[i];
            observer.observe(dom, config);
        }
    }

    // 点击后重新监听，防止异步添加的dom监听不到
    var setTimeFun
    $('body').mousedown(function(){
        if(setTimeFun){
            clearTimeout(setTimeFun)
        }
        observerClick.observe(document, config);
    }).mouseup(function(){
        setTimeFun = setTimeout(function(){
            observerClick.disconnect();
        },2000)
    })
}
clickWinStatistics()


function Visitlazy() {
    var that = this
    var showData = [];
    that.lazy = function (dom) {
        return function () {
            showData = [];
            var imagesList = dom ? dom.getElementsByClassName("visit-lazy") : document.getElementsByClassName("visit-lazy"); // 获取所有元素列表
            var length = imagesList.length;
            for (var i = 0; i < length; i++) {
                if (imagesList[i]) {
                    const rect = imagesList[i].getBoundingClientRect();
                    if (
                        rect.top >= 0 &&
                        rect.left >= 0 &&
                        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
                        rect.right <= (window.innerWidth || document.documentElement.clientWidth) &&
                        imagesList[i].offsetParent !== null) {

                        if (!imagesList[i].classList.contains("visited")) {
                            imagesList[i].classList.add("visited");
                            that.pushData(imagesList[i].dataset);
                        }
                    } else {
                        imagesList[i].classList.remove("visited");
                    }
                }
            }
            that.showPush();
        };
    }
    that.pushData = function (dataset) {
        var videoId = dataset.vlazyId;
        var category = dataset.vlazyCategory;
        var seat = dataset.vlazySeat;
        var uid = Param.uid;
        if (uid == 0) {
            uid = -1;
        }
        showData.push({
            uid: uid,
            vid: videoId,
            category: category,
            port: Param.videoShowLogPort,
            seat: seat
        })

        if (showData.length == 10) {
            this.showPush();
            showData = [];
        }
    }
    that.showPush = function () {
        if (showData.length === 0) return

        var logHost = 'cn-shanghai.log.aliyuncs.com';
        var logProject = 'huke';
        var logStore = 'video_show_record';
        var logger = new window.Tracker(logHost, logProject, logStore);

        logger.push('row_data', JSON.stringify(showData));
        logger.logger();
    }
    that.clickPush = function (dataset) {
        var videoId = dataset.vlazyId;
        var category = dataset.vlazyCategory;
        var seat = dataset.vlazySeat;
        var logHost = 'cn-shanghai.log.aliyuncs.com';
        var logProject = 'huke';
        var logStore = 'video_show_click_record';
        var logger = new window.Tracker(logHost, logProject, logStore);

        var uid = Param.uid;
        if (uid == 0) {
            uid = -1;
        }
        logger.push('uid', uid);
        logger.push('vid', videoId);
        logger.push('category', category);
        logger.push('port', Param.videoShowLogPort);
        logger.push('seat', seat);
        logger.push('url_route', Url.spmprefix);
        logger.logger();
    }
    that.throttle = function (func, wait, options) {
        var _this, args, timeout;
        var old = 0; //时间戳
        //如果没有options就将其设置为空对象
        if (!options) options = {};
        var later = function () {
            old = new Date().valueOf();
            timeout = null;
            func.apply(_this, args);
        };
        return function () {
            _this = this;
            args = arguments;
            var now = new Date().valueOf();
            if (options.leading === false && !old) {
                old = now;
            }
            if (now - old > wait) {
                // 第一次直接执行
                if (timeout) {
                    clearTimeout(timeout);
                    timeout = null;
                }
                func.apply(_this, args);
                old = now;
            } else if (!timeout && options.trailing !== false) {
                //最后一次也被执行
                timeout = setTimeout(later, wait);
            }
        };
    }
}
// 声明构造函数
var visitlazy = new Visitlazy()
visitlazy.throttle(visitlazy.lazy(), 2000, {
    leading: true, //是否立即执行
    trailing: true, //最后一次是否执行
    //两者不能同为false,否则就会产生bug,会导致触发事件立即执行一次后就失效了!
})
// 添加滚动监听事件
window.addEventListener("scroll", visitlazy.throttle(visitlazy.lazy(), 2000, {
    leading: true,
    trailing: true,
}), false);
// 点击监听事件
$('html').on('click','.visit-lazy',function(){
    visitlazy.clickPush($(this)[0].dataset)
})